首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DevExpress gridLookUpEdit的多列默认值

DevExpress gridLookUpEdit的多列默认值
EN

Stack Overflow用户
提问于 2016-05-27 22:28:32
回答 1查看 1.4K关注 0票数 0

我使用DevExpress 15.2的gridLookUpEdit来显示数据。我已经解决了用这种方式显示多列的选定值的问题。

代码语言:javascript
复制
 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个不同的单元格值来添加自定义显示文本。我想对默认值做完全相同的事情。加载后,我想显示此模式中可能的第一行。我知道,我可以这样获得第一行:

代码语言:javascript
复制
gridLookUpEdit1.EditValue = gridLookUpEdit1.Properties.GetKeyValue(0);

我应该在提到的事件中调用吗?有没有什么有效的方法来解决这个问题?

致以问候。

EN

回答 1

Stack Overflow用户

发布于 2016-05-28 19:11:27

自定义显示文本不显示在加载中,因为gridLookUpEdit.Properties.View没有加载DataSource,您有两个解决方案来检查这一点:

1-在选择默认值之前访问DataSource到gridLookUpEdit.Properties.View,如下所示:

代码语言:javascript
复制
gridLookUpEdit.Properties.View.GridControl.BindingContext = new BindingContext(); 
gridLookUpEdit.Properties.View.GridControl.DataSource = gridLookUpEdit.Properties.DataSource;
gridLookUpEdit.EditValue = gridLookUpEdit.Properties.GetKeyValue(0);

2 -You可以更改CustomDisplayText事件中的代码,如下所示:

代码语言:javascript
复制
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();
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37486041

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档