LookUpEdit DisplayFormat FormatString
本文关键字:FormatString DisplayFormat LookUpEdit | 更新日期: 2023-09-27 18:24:29
我在使用DevExpress LookUpEdit DisplayFormat时遇到了一个简单的问题。我想在lookUpEdit中获得如下结果:
文档类型(.doc)
文档类型(.docx)
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;
您可以使用以下技巧(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]);
}
如果我没记错的话,LookUpEdit不支持此功能。
我只需构建一个值为"Document type(.docx)"、"DocumentType(.xy)"的列表,并将其绑定到控件。
类似的东西
var types = defaultExtensionsList.Split(';').Select(s => "DocumentType (*." + s + ")").ToList();