In my Windows Forms Application (C# 2005), I am using ListBox but it have a problem when I remove item.
listBox.Items.RemoveAt(1); ---> Items collection cannot be modified when the DataSource property is set.
Note: It have just appeared when I used listbox.DataSource = dataTable;
If I dont use DataSource --> Everything is OK
For(int i=0; i<10; i++)
listBox.Items.RemoveAt(1); ---> OK
"Microsoft supports thi datasource for us, why dont we use it? Could you explain to me?"
I think that the logic is like fallows. When you bind a DataTable to a ListBox what you get is a reference to the DataTable if you change any value in the ListBox you would be actually afecting any other object that is also bindded to that DataTable. So in my opinion that might be the motive. Also in OOP I don't think that is 'good practice' to change tha value of an object indirectly. (e.i Changing the value of the ListBox you are inded changing the value of the DataSet).
I don't know if this is the best way to do it but my idea is to create a class for mapping the results that you get from the database and since the ListTextBox.Items.Add takes an object as parameter then you can pass an instance of that class that you had created.