Jackyef
Jackyef

Reputation: 5012

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:

Properties of said Combobox

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:

Perfectly fine combobox

The problem occurs after I changed the selected item to the 2nd one in the list, and tried changing it again:

Messed up

When I tried selecting System.Data.DataRowView, this error appeared: An error

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!

Upvotes: 0

Views: 1815

Answers (1)

Jackyef
Jackyef

Reputation: 5012

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!

Upvotes: 1

Related Questions