I want my combo box's value to be .Items[i]. Item is of type DataRowView.

My combo boxes are binded by database. Value member of cmbx is IDplayer in database. Selected value is playersBindingSource - IDplayer.

This is the error: Column 'IDplayer' is constrained to be unique. Value '2' is already present.

//cmb = Combo Box;
//cmbPlayers = Binding List of combo boxes

int i = 0;
foreach (ComboBox cmb in cmbPlayers)
    cmb.SelectedItem = cmb.Items[i]; // ERROR HAPPENS

Edited by Dino000

5 Years
Discussion Span
Last Post by Mike Askew

Im confused at what the issue is, as were the people on StackOverflow when you asked them the identical question.

Please clarify.

Edited by Mike Askew


Then I'm really sorry. I don't know why I'm getting the exception which I named above. The exception is marked by the comment in code. Any ideas why it throw the exception?


The exception is thrown because the field IDplayer is a primary key field which is unique. You are trying to add the value '2' to a field withing that column and it already exists. Therefore the exception is thrown.

As to why it is thrown on that line, I can't say without understanding further.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.