RubenPieters

I have a listbox that contains data from a datatable and the value/display member is the ID key, but when I select something inside it it gives the following error:

System.Data.ConstraintException was unhandled
Message="For the column KaartID applies the restriction that it has to be unique. The value 4 is already present."



Re: Visual C# Express Edition I can't select items in a listbox with ID key data

Figo Fei - MSFT

Hi,

The cause is that ID is the unique key of the datatable which can't be duplicated.

Pls check what operation have you applied to the listBox about this unique column data

Thanks






Re: Visual C# Express Edition I can't select items in a listbox with ID key data

RubenPieters

Figo Fei - MSFT wrote:

Hi,

The cause is that ID is the unique key of the datatable which can't be duplicated.

Pls check what operation have you applied to the listBox about this unique column data

Thanks

what do you mean with operation what it does with the data but if I just click the data in the listbox it says the same error

kaartIDListBox1.SelectedIndex = 0;





Re: Visual C# Express Edition I can't select items in a listbox with ID key data

Figo Fei - MSFT

Hi,

Did you add extra item besides the data from database

Could you show the databinding snippet of code or what else you do with that listBox

Thanks






Re: Visual C# Express Edition I can't select items in a listbox with ID key data

RubenPieters

 Figo Fei - MSFT wrote:

Hi,

Did you add extra item besides the data from database

Could you show the databinding snippet of code or what else you do with that listBox

Thanks

I didn't add any other items besides that from the database.

kaartIDListBox1.SelectedIndex = -1;

in form1_load

this.kaartIDListBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.targetInfoBindingSource, "KaartID", true));

this.kaartIDListBox1.DataSource = this.targetInfoBindingSource;

this.kaartIDListBox1.DisplayMember = "KaartID";

in where everything is what the length and such of something is

and here and there this:

kaartIDListBox1.SelectedIndex = -1;

or this:

kaartIDListBox1.SelectedIndex = 0; (with sometimes different nrs then 0 ofc)

I have a same listbox that has everything the same (except from where it get its data from) but there I can select inside it etc, I'm currently trying to find where there is a difference :/





Re: Visual C# Express Edition I can't select items in a listbox with ID key data

Figo Fei - MSFT

 RubenPieters wrote:

this.kaartIDListBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.targetInfoBindingSource, "KaartID", true));

this.kaartIDListBox1.DataSource = this.targetInfoBindingSource;

this.kaartIDListBox1.DisplayMember = "KaartID";

What about:

this.kaartIDListBox1.DataSource = this.targetInfoBindingSource;

this.kaartIDListBox1.DisplayMember = "KaartID";

this.kaartIDListBox1.ValueMember = ...;

If it doesn't work, check if the targetInfoBindingSource's configration and the data in the database is correct.

Thank you.






Re: Visual C# Express Edition I can't select items in a listbox with ID key data

RubenPieters

the valuemember is KaartID also