2012-11-11 68 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; 

你可以,當然,對於添加事件有條件的。