细胞显示值部件(ID),而不是显示部件 [英] Cells show the value member (ID) instead Display member

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

问题描述

我目前正与C#和我有以下的code设置组合框列内DGV:

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);

一切工作正常,但DGV只显示该成员的值当细胞具有焦点:

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?

推荐答案

我由我自己发现的错误。基本上在DGV的数据源的栏目日型字节(TINYINT在SQL)的。 当code尝试创建数据表,填补了DGV组合框列; ID类型为整数。

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".

解决的办法是检查ID VS列源的数据类型。如果有型动物;抛出一个异常pviously检查$ P $。

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天全站免登陆