2012-11-11 22 views
0

随着FireMonkey和几个项目的TListBox ...如何防止/取消在TListBox中更改项目?

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

就像我们可以用了TListView的做事件:OnChanging

onmousedown事件&的onkeydown事件将改变前触发(项目值仍然为电流/老选定的项目,而不是为选择)...

所以我可以存储的存储easill当前列表框的ItemIndex ...和变更后,搬回它..但是这仅仅是可怕的,肮脏的,...

无论如何做得很好吗?

回答

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; 

你可以,当然,对于添加事件有条件的。