G
Guest
Working on a windows form, I am trying to bind a listbox to a dataset and
want to set the displaymember & Valuemember properties of the listbox so that
I can retrieve the selectedvalue from a selecteditem in the listbox.
My code is very simple:
lstReports.DataBindings.Clear()
lstReports.DataSource = dsDataSet.Tables("Reports")
lstReports.DisplayMember = "ReportDescription"
lstReports.ValueMember = "ReportsKey"
However, I keep getting the following error:
"Cannot modify the Items collection when the DataSource property is set."
and my application crashes.
I have used the displaymember & valuemember successfully with comoboboxes
and I have read the MSDN Help which suggests I should be able to do the same
with a listbox, but unfortunately I get this error.
Has any else come across this?
Any idea's as to how I resolve this?
Any help would really appreciated.
want to set the displaymember & Valuemember properties of the listbox so that
I can retrieve the selectedvalue from a selecteditem in the listbox.
My code is very simple:
lstReports.DataBindings.Clear()
lstReports.DataSource = dsDataSet.Tables("Reports")
lstReports.DisplayMember = "ReportDescription"
lstReports.ValueMember = "ReportsKey"
However, I keep getting the following error:
"Cannot modify the Items collection when the DataSource property is set."
and my application crashes.
I have used the displaymember & valuemember successfully with comoboboxes
and I have read the MSDN Help which suggests I should be able to do the same
with a listbox, but unfortunately I get this error.
Has any else come across this?
Any idea's as to how I resolve this?
Any help would really appreciated.