2012-02-12 63 views
1

我有簡單的問題DevExpress LookUpEdit DisplayFormat。我想實現在lookUpEdit結果一樣:
文檔類型(.DOC)
文檔類型(
的.docx)LookUpEdit DisplayFormat格式字符串

const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt"; 
//... 
var column = new LookUpColumnInfo("Column", "Extensions") 
{ 
    Visible = true, 
    //FormatType = FormatType.Custom, 
    //FormatString ="Document type (*.{0})", 
    Alignment = HorzAlignment.Near 
}; 
ExtensionsLookup.Properties.DisplayFormat.FormatType = FormatType.Custom; 
ExtensionsLookup.Properties.DisplayFormat.FormatString = "Document type (*.{0})"; 
ExtensionsLookup.Properties.EditFormat.FormatType = FormatType.Custom; 
ExtensionsLookup.Properties.EditFormat.FormatString = "Document type (*.{0})"; 
ExtensionsLookup.Properties.Columns.Add(column); 

var bindingList = defaultExtensionsList.Split(';').ToList(); 
ExtensionsLookup.Properties.DataSource = bindingList; 

回答

2

您可以使用下面的技巧(RepositoryItemLookUpEdit.GetNotInListValue事件):

const string defaultExtensionsList = "doc;docx;xlsx;xls;pdf;txt"; 
//... 
var columnID = new LookUpColumnInfo("Column", "IDs") { Visible = false }; 
var columnToDisplay = new LookUpColumnInfo("Display", "Extensions"); 

lookUpEdit.Properties.Columns.AddRange(new LookUpColumnInfo[] { columnID, columnToDisplay }); 
lookUpEdit.Properties.ValueMember = "Column"; 
lookUpEdit.Properties.DisplayMember = "Display"; 
lookUpEdit.Properties.TextEditStyle = TextEditStyles.DisableTextEditor; 
lookUpEdit.Properties.GetNotInListValue += OnGetNotInListValue; 

var bindingList = defaultExtensionsList.Split(';').ToList(); 
lookUpEdit.Properties.DataSource = bindingList; 
//... 
void OnGetNotInListValue(object sender, GetNotInListValueEventArgs e) { 
    if(e.FieldName == "Display") 
     e.Value = string.Format("Document type (*.{0})", 
      ((IList<string>)lookUpEdit.Properties.DataSource)[e.RecordIndex]); 
} 
+0

hank。這幾乎是我所需要的。 var columnToDisplay = new LookUpColumnInfo(「Display」,「Extensions」); ExtensionsLookup.Properties.Columns.Add(columnToDisplay); ExtensionsLookup.Properties.GetNotInListValue + = OnGetNotInListValue;爲什麼幾乎? EditValue未格式化:)我將接受:P. – kayz1 2012-02-13 19:20:43

0

如果我沒有記錯,LookUpEdit不支持此功能。

我只是建立一個值爲「文檔類型(.docx)」,「文檔類型( .xy)」的列表並將其綁定到控件。

喜歡的東西

var types = defaultExtensionsList.Split(';').Select(s => "DocumentType (*." + s + ")").ToList(); 
+0

我知道,但我需要能夠與數據操作(刪除,添加獨特的),所以我認爲這可以通過FormatString完成。這樣我就不需要管理一個字典或兩個列表。 – kayz1 2012-02-13 17:22:02