473,513 Members | 2,560 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListBox Control: DataSource, DisplayMember, ValueMember properties



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.ArgumentException below:

================================================== =====
System.ArgumentException: Cannot modify the Items collection when the
DataSource property is set.

at System.Windows.Forms.ListBox.CheckNoDataSource()
at System.Windows.Forms.ListBox.Sort()
at System.Windows.Forms.ListBox.EndUpdate()
at System.Windows.Forms.ListBox.SetItemsCore(IList value)
at System.Windows.Forms.ListControl.DataManager_ItemC hanged(Object
sender, ItemChangedEventArgs e)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring 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!
Nov 15 '05 #1
0 2127

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

Similar topics

3
2381
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 writing a usercontrol which displays the typical two listboxes and the ability to move items from one to the other. The listboxes are populated...
2
1990
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 selecteditem in the listbox. My code is very simple: lstReports.DataBindings.Clear() lstReports.DataSource = dsDataSet.Tables("Reports")...
1
1915
by: Zoury | last post by:
Hi there! :O) I have a WebService that contains the following struct definition. this struct is defined right after the WebService class, ie : //*** namespace mynamespace { public class MyWebService : WebService {// code here..} public struct Record {
2
1959
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 dataset table. Now when I change the selection in the lstSchItem the comboxes are staying the same and not reflecting the changes. I tried...
5
7833
by: Dave | last post by:
Hi all, Is it possible to populate a listbox from a hashtable (complexbind) where the ValueMember of the listbox maps to the "key" member of the hashtable AND the DisplayMember of the listbox maps to the "value" member of the hashtable? I found that it is impossible to use a hashtable as a listbox datasource directly (from trial and error)...
7
4519
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 ASP.Net stuff when I need a Windows Form control. I've seen dual listbox populators in countless Windows applications, and have seen them run very...
4
1376
by: P K | last post by:
Hi, I have two listboxes on my form. One has a list of available values while the other is a list of selected values. So I select a value from list 1 and add it to list 2 when "add" button is clicked. I can also select a value from list 2 and remove it on clicking "Remove" button, which would again add it to list 1.
1
2756
by: A. Spiehler | last post by:
I'm trying to fill a listBox control with string members from an array of objects. I think using data binding is supposed to be the easiest way to do this. I've never used data binding before and am having trouble getting it to do anything. The relevant code is below, followed by a better explanation of what I'm trying to do. // pseudocode...
5
34012
by: =?Utf-8?B?QmVu?= | last post by:
How would you add an item with its DisplayMember and ValueMember without binding to a datatable or dataview like: listbox.DisplayMember = "name"; listbox.ValueMember = "recid"; listbox.DataSource = dt; listbox.Items.Add(name) can only add the DisplayMember. Thanks,
0
7270
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7178
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7397
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
5704
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5103
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4759
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3255
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
817
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.