简体   繁体   English

组合框显示更改选择后的System.Data.DataRowView

[英]ComboBox showing System.Data.DataRowView after changing selection

I have been looking at all the other questions similar to this one and they just don't seem to help me with my particular problem. 我一直在寻找与这个问题类似的所有其他问题,但是它们似乎并没有帮助我解决我的特定问题。

I am using a Combobox with the following properties: 我正在使用具有以下属性的组合框:

所述组合框的属性

The purpose of the Combobox is simple, it is taking all the values of an unique column in a table, and present them as options. 组合框的用途很简单,它将表格中唯一列的所有值都作为选项显示。 The column's name is "nim". 该列的名称为“ nim”。

Upon initialization, the combobox loaded just fine: 初始化后,组合框加载就好了:

完美的组合框

The problem occurs after I changed the selected item to the 2nd one in the list, and tried changing it again: 在将所选项目更改为列表中的第二项,然后尝试再次更改它之后,出现了问题:

弄乱

When I tried selecting System.Data.DataRowView, this error appeared: 当我尝试选择System.Data.DataRowView时,出现此错误: 一个错误

I have been playing around with the code to no avails. 我一直在玩代码无济于事。 I didn't write any code concerning the combobox. 我没有编写任何有关组合框的代码。 I just assign the DataSource, DisplayMember, and ValueMember from the properties window manually. 我只是从属性窗口手动分配DataSource,DisplayMember和ValueMember。

The only code concerning combobox is these: 关于组合框的唯一代码是:

private void comboNIM_SelectedIndexChanged(object sender, EventArgs e)
    {
        //selectedNIM = ((DataRowView)comboNIM.SelectedItem).Row["nim"] as String;
        selectedNIM = comboNIM.SelectedValue.ToString();

    }

Any help will be really appreciated! 任何帮助将不胜感激! Thank you! 谢谢!

So..., I have found a solution for this particular problem. 所以...,我找到了解决此特定问题的方法。

I deleted the ComboBox, and then created a new one. 我删除了ComboBox,然后创建了一个新的。 Then I just assign the properties programmatically. 然后,我只是以编程方式分配属性。 cb.DisplayMember = 'nim'; cb.ValueMember = 'nim'; cb.DataSource = mahasiswaBindingSource;

Apparently, leaving the properties window unedited solved the problem! 显然,不编辑属性窗口可以解决问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM