473,377 Members | 1,119 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,377 software developers and data experts.

Listbox, DataBinding & ValueMember Error

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.
Jul 21 '05 #1
2 1965
Supa,

The listbox has a itemscollection. Probably are you setting/changing that
one somewhere.

(In the designer is the name collection).

I hope this helps

Cor
Jul 21 '05 #2
Thanks for the suggestion, but it wasn't that.

I had to re-organize the order in which I declared the value member, the
display member & the datasource. Once I put them in the following order, the
data binding worked ok.

lstReports.DataBindings.Clear()
lstReports.ValueMember = "ReportsKey"
lstReports.DataSource = dsDataSet.Tables("Reports")
lstReports.DisplayMember = "ReportDescription"

Strange, but true !!

"Cor Ligthert" wrote:
Supa,

The listbox has a itemscollection. Probably are you setting/changing that
one somewhere.

(In the designer is the name collection).

I hope this helps

Cor

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
2
by: Alpha | last post by:
I have a window application. On one of the form, there is a listbox and a few combox. The lstSchItem has a dataview as a datasource. The comboxes are bind to its selected value but through the...
2
by: Young J. Putt | last post by:
I've got a list box bound to a Datatable, like this: lstProjects.DataSource = m_oProjectSet.DataTable lstProjects.DisplayMember = "ProjectDesc" lstProjects.ValueMember = "ProjectID" I want to...
2
by: tangokilo | last post by:
Hello and thanks for your help, I have the following Listbox created in VisualStudio 2003 designer, desiring to select multiple entries from that list: -------------------------------...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
2
by: Supa Hoopsa | last post by:
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...
3
by: Dan Slaby | last post by:
I have a webservice that I want to populate a combobox on a windows form. The webservice creates the correct XML output, but when I attempt to bind it to a combobox I get this error: Additional...
10
by: Ben | last post by:
Hi Im trying to get the value from a listbox, i have the below code to get the text: txtEntity.Text = ListBox1.Text But do not seem to be able to retrieve the data that i set as the value...
2
by: Pat | last post by:
I'm a newbie to c# and could use some help - been banging my head on the keyboard for 3 days now. I have an unbound listbox that I'm populating this way: 1. loop through a datatable and load...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.