我使用DevExpress 15.2的gridLookUpEdit来显示数据。我已经解决了用这种方式显示多列的选定值的问题。
private void gridLookUpEdit_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
GridLookUpEdit edit = sender as GridLookUpEdit;
int theIndex = edit.Properties.GetIndexByKeyValue(edit.EditValue);
if (edit.Properties.View.IsDataRow(theIndex))
{
someObject row = (someObject)edit.Properties.View.GetRow(theIndex);
e.DisplayText = row.value1 + ": " + row.value2 + " " +row.value3;
}
}如你所见,我使用了3个不同的单元格值来添加自定义显示文本。我想对默认值做完全相同的事情。加载后,我想显示此模式中可能的第一行。我知道,我可以这样获得第一行:
gridLookUpEdit1.EditValue = gridLookUpEdit1.Properties.GetKeyValue(0);我应该在提到的事件中调用吗?有没有什么有效的方法来解决这个问题?
致以问候。
发布于 2016-05-28 19:11:27
自定义显示文本不显示在加载中,因为gridLookUpEdit.Properties.View没有加载DataSource,您有两个解决方案来检查这一点:
1-在选择默认值之前访问DataSource到gridLookUpEdit.Properties.View,如下所示:
gridLookUpEdit.Properties.View.GridControl.BindingContext = new BindingContext();
gridLookUpEdit.Properties.View.GridControl.DataSource = gridLookUpEdit.Properties.DataSource;
gridLookUpEdit.EditValue = gridLookUpEdit.Properties.GetKeyValue(0);或
2 -You可以更改CustomDisplayText事件中的代码,如下所示:
private void gridLookUpEdit_CustomDisplayText(object sender, DevExpress.XtraEditors.Controls.CustomDisplayTextEventArgs e)
{
GridLookUpEdit edit = sender as GridLookUpEdit;
int theIndex = edit.Properties.GetIndexByKeyValue(edit.EditValue);
if (theIndex >= 0)
{
DataRowView row = (DataRowView)edit.Properties.GetRowByKeyValue(edit.EditValue);
e.DisplayText = row[0].ToString() + ": " + row[1].ToString() + " " + row[2].ToString();
}
}https://stackoverflow.com/questions/37486041
复制相似问题