单元格显示值成员(ID),而不是显示成员 [英] Cells show the value member (ID) instead Display member

查看:187
本文介绍了单元格显示值成员(ID),而不是显示成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#,我有以下代码在DGV内设置一个ComboBox列:

  / /添加组合框的值
dgvcbGeneric.DataSource = dtDataSource;
dgvcbGeneric.ValueMember =ID;
dgvcbGeneric.DisplayMember =Value;
dgvcbGeneric.DataPropertyName = strColumn;
dgvcbGeneric.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;

dgvcbGeneric.DisplayStyleForCurrentCellOnly = true;
// vGenericCMB.SortMode = DataGridViewColumnSortMode.Automatic

dgvcbGeneric.DefaultCellStyle.NullValue = columns [strActualColumn] .nullFormat;

//添加DGV的新ComboBoxColumn
dgvLink.Columns.Add(dgvcbGeneric);



所有功能都可以正常工作,但是当单元格有焦点时,DGV仅显示成员值:





有人可以解释为什么会出现这个问题?

解决方案

我自己发现错误。基本上在DGV的DataSource中,Day列的类型为Byte(SQL中为tinyint)。
当代码尝试创建DataTable以填充DGV ComboBox列; ID类型为整数。



解决方案是检查ID与Data Source的DataType。如果是不同的;抛出异常以检查以前的检查。


I'm currently working with C# and I have the following code to set a ComboBox column inside a DGV:

// Add the values of the combo box
dgvcbGeneric.DataSource = dtDataSource;
dgvcbGeneric.ValueMember = "ID";
dgvcbGeneric.DisplayMember = "Value";
dgvcbGeneric.DataPropertyName = strColumn;
dgvcbGeneric.DisplayStyle = DataGridViewComboBoxDisplayStyle.ComboBox;

dgvcbGeneric.DisplayStyleForCurrentCellOnly = true;
// vGenericCMB.SortMode = DataGridViewColumnSortMode.Automatic

dgvcbGeneric.DefaultCellStyle.NullValue = columns[strActualColumn].nullFormat;

// Add the new ComboBoxColumn of the DGV
dgvLink.Columns.Add(dgvcbGeneric);

All works fine, but the DGV only show the member value when the cell has the focus:

Someone can explain me why this issue is happening?

解决方案

I found the error by myself. Basically in the DataSource of the DGV the column "Day" was of type "Byte" (tinyint in SQL). When the code try to create the DataTable to fill up the DGV ComboBox Column; the ID type is "Integer".

The solution was check the DataType of the ID vs the column source. If are differents; throw an exception to check previously.

这篇关于单元格显示值成员(ID),而不是显示成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆