I have a ListBox to which I am assigning a DataTable as a DataSource, as
shown below.
=============== =============== =============== ==========
DataTable VendorData = new DataTable();
// Code here retrieves Data and populates
// the VendorData DataTable.
listBox_Vendor. DataSource = VendorData;
listBox_Vendor. ValueMember = "ID";
listBox_Vendor. DisplayMember = "Name";
=============== =============== =============== ==========
This code works fine when there is only one entry in the DataSource.
When the number of entries is greater than one, however, it throws the
System.Argument Exception below:
=============== =============== =============== ==========
System.Argument Exception: Cannot modify the Items collection when the
DataSource property is set.
at System.Windows. Forms.ListBox.C heckNoDataSourc e()
at System.Windows. Forms.ListBox.S ort()
at System.Windows. Forms.ListBox.E ndUpdate()
at System.Windows. Forms.ListBox.S etItemsCore(ILi st value)
at System.Windows. Forms.ListContr ol.DataManager_ ItemChanged(Obj ect
sender, ItemChangedEven tArgs e)
at System.Windows. Forms.ListContr ol.SetDataConne ction(Object
newDataSource, BindingMemberIn fo newDisplayMembe r, Boolean force)
at System.Windows. Forms.ListContr ol.set_ValueMem ber(String value)
=============== =============== =============== ==========
I don't quite understand what's going on here. There is no editing done
to the items of the ListBox anywhere.
Any assistance is immensely appreciated.
- J
*** Sent via Developersdex
http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!