【问题标题】:How to prevent/cancel an item to change in a TListBox?如何防止/取消要在 TListBox 中更改的项目?
【发布时间】:2012-10-31 02:16:04
【问题描述】:
使用 FireMonkey 和 TListBox 中的几个项目...
我希望能够允许/取消项目更改...
就像我们可以使用 TListView 的事件一样:OnChanging
事件 OnMouseDown 和 OnKeyDown 在更改之前触发(项目值仍然适用于 当前/旧 选定的项目,而不是 新 选择 em>)...
所以我可以存储 easill 存储当前的 ListBox ItemIndex... 并在更改后移回它.. 但这太糟糕了,肮脏,...
不管怎样都做得很好?
【问题讨论】:
标签:
delphi
listbox
delphi-xe2
onchange
firemonkey
【解决方案1】:
您最好创建一个自定义组件以通过覆盖 SetItemIndex 方法来添加功能:
type TCustomListBox = class(TListBox)
protected
procedure SetItemIndex(Value: Integer);override;
end;
procedure Register;
...
procedure Register;
begin
RegisterControls('Custom', [TCustomListBox]);
end;
procedure TCustomListBox.SetItemIndex(Value: Integer);
begin
if <condition> then
inherited
end;
initialization
RegisterFMXClasses([TCustomListBox]);
end;
当然,您可以为条件添加一个事件。