细胞显示值部件(ID),而不是显示部件部件、而不是、细胞、ID

2023-09-07 10:23:37 作者:眉间杀气

我目前正与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.