2012-10-24 26 views
0

我正在使用DevExpress。 在我的項目中我有控制(textEdit),EditValue綁定到「int」類型的屬性。 問題是控制只允許輸入數字。在TextEdit中設置字符串,它只允許int

我的任務是:當窗體處於編輯模式時,文本編輯應該顯示單詞「自動」,並且只有在安全按鈕按下後應該生成編號。 現在編輯模式文本框顯示「0」,是否可以在「0」的情況下顯示「自動」。

,該場所,到文本框的綁定:

int fEventNr; 
public int EventNr { 
    get { return fEventNr; } 
    set { SetPropertyValue<int>("EventNr", ref fEventNr, value); } 
} 

一切正常,除了它顯示「0」,我不知道如何讓他出示「自動」 也許有人有任何想法嗎?

回答

0

這是你的問題的解決方案:

textEdit1.Properties.CustomDisplayText += new Properties_CustomDisplayText; 


void Properties_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e) 
{ 
    if (yourCondition) 
     e.DisplayText = "Automatic"; 
} 
0
txtEdit.Properties.NullText = "Automatic"; 
txtEdit.EditValue = null; 

考慮更改public int EventNrpublic int? EventNr,這樣你可以肯定的是,用戶沒有提供任何值,如果的EditValue爲空,你應該產生它「自動」阿里:) 我認爲這是一個糟糕的做法,將0視爲[未設定值]。這就是他們發明null的原因。

0

在屬性面板上,轉到屬性 - >Mask . Set "MaskType" to RegEx並將"EditMask"設置爲\d*。如果您不希望整數從零開始,則將"EditMask"改爲[1-9]+\d*。 或者你也可以通過代碼:

this.textEditIntegersOnly.Properties.Mask.EditMask = "[1-9]+\\d*"; 
this.textEditIntegersOnly.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.RegEx;