Hi,
I noticed a strange behaviour of the ListBox control in C# when I bind it to an Access database: if I try to set its "Sorted" property to true, the exception "Impossible to modify Items collection when DataSource property is set" is thrown during the execution.
The strange thing is that, if I replace the ListBox with a ComboBox control, the program functions correctly (I can set its Sorted property to true without exceptions).
Is it a bug or there is a reason for this different behaviour between ListBox and ComboBox?
Thank you very much
P.S.: These are the statements regarding my problem:
I noticed a strange behaviour of the ListBox control in C# when I bind it to an Access database: if I try to set its "Sorted" property to true, the exception "Impossible to modify Items collection when DataSource property is set" is thrown during the execution.
The strange thing is that, if I replace the ListBox with a ComboBox control, the program functions correctly (I can set its Sorted property to true without exceptions).
Is it a bug or there is a reason for this different behaviour between ListBox and ComboBox?
Thank you very much
P.S.: These are the statements regarding my problem:
Code:
cboCities.Parent = this;
cboCities.Size = new Size(100, 30);
cboCities.Location = new Point(10, 10);
cboCities.Sorted = true;
cboCities.DataSource = dtCities; // DataTable object
cboCities.ValueMember = "IDCity"; // 1st field of the table
cboCities.DisplayMember = "NameCity"; // 2nd field of the table
lstCities.Parent = this;
lstCities.Size = new Size(100, 100);
lstCities.Location = new Point(cboCities.Left + cboCities.Width + 10, cboCities.Top);
// If you remove the comment to the next statement,
// an exception will be thrown during execution
// lstCities.Sorted = true;
lstCities.DataSource = dtCities; // DataTable object
lstCities.ValueMember = "IDCity"; // 1st field of the table
lstCities.DisplayMember = "NameCity"; // 2nd field of the table