如何防止/取消TListBox中的项目更改?

时间:2012-11-11 10:52:23

标签: delphi listbox delphi-xe2 onchange firemonkey

使用 FireMonkey 以及TListBox中的多个项目......

我希望能够允许/ 取消项目更改 ...

就像我们可以使用TListView的事件一样:OnChanging

事件OnMouseDown&amp; OnKeyDown在更改之前触发(项目值仍为当前/旧所选项目,而不是 选择)... < / p>

所以我可以存储easill存储当前的ListBox ItemIndex ...并在更改之后,回到它...但这只是可怕,脏,......

无论如何要做得好吗?

1 个答案:

答案 0 :(得分:0)

最好通过覆盖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;

当然,您可以为条件添加事件。

相关问题