473,654 Members | 3,239 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.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!
Nov 15 '05 #1
0 2140

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

Similar topics

3
2407
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 with my custom objects (SwapItem), which simply
2
2013
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") lstReports.DisplayMember = "ReportDescription" lstReports.ValueMember = "ReportsKey"
1
1926
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
1963
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 changing the binding to the dataview.table but the comboxes are still not changing to reflect the...
5
7839
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) and tried DirectCast-ing to an arraylist without any success. Before I spend anymore time in vain...
7
4529
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 fast, so I figured this would be extremely popular. Here's how it should work:
4
1378
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
2770
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 start public delegate string StepMethod();
5
34067
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
8379
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8709
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8494
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8596
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7309
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2719
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

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.