简体   繁体   中英

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

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: 一个错误

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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