2013-05-15 22 views
1

我們正在使用devexpress在Delphi 2006中工作。delphi cxgrid限制字符

我們有一個cxGrid。 我們希望限制數字列的值輸入,整數在0到999之間。 如果我將屬性類型設置爲SpinEdit,初始值始終爲0,這是不需要的。

因此,我留下了null列的屬性值,並將列的數據綁定上的數據類型設置爲Smallint。這在大多數情況下都是有效的,但是卻是'e'和'。'而'+'和' - '仍然可以輸入到導致異常的列中。

是排除'e'和'。'的簡單方法。和'+'和' - '是否被輸入到列中?

回答

0

通過將UseNullString設置爲true,可以防止初始值爲0。

的不需要的字符的輸入可以通過

procedure TForm1.ViewEditKeyPress(Sender: TcxCustomGridTableView; AItem: TcxCustomGridTableItem; 
    AEdit: TcxCustomEdit; var Key: Char); 
begin 
    if AItem = TheColumnWithSpinEdit then 
    if (not (Key in ['0'..'9',#8])) then Key := #0; 
end; 
+0

由於bummi處理。 UseNullString屬性不存在於我們的cxgridDBColumn中,但是我在視圖上實現了ViewEditKeyPress代碼,並且它的工作方式類似於魅力,儘管AItem = TheColumnWithSpinEdit從未驗證,所以我將其更改爲AItem.Caption = TheColumnWithSpinEdit.Caption。我也嘗試鑄造AItem作爲TcxGridDBColumn無濟於事。再次感謝。 – jmskippy