473,549 Members | 2,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do you set the value member of a combo box

I have recently migrated to VS.Net 2005, and I am struggling to do something
very basic with the combo box. I want to manually loop through a data table
and add both the display text and the value manually. The reason I cannot
bind the combo box to my data table is that there are more than one field
that I want to combine to be the display member. So what I had to do was
create yet another data table at run time (or an array list) and combine the
columns in my new data table so it would display the way I want it to. This
is much more code than simply lookping through my original data table and
adding the item and setting the value manually. I don't want to have to do
this for every combo box in the application. is it possible to set the value
member of a combo box item without binding it to a data source?

I also noticed that when I set the display member to a field that has a
space in it (i.e. [last name]) the value member displays.
Jun 20 '07 #1
1 2571
Bind to an array of objects (or fill the Combo Items collection with
objects) whose class implements a property (let's name it 'Text') which
build the display information from the various needed part of the object,
then set that property name ('Text' in our example) as the display member of
the combo.

/LM
"mfm" <mf*@discussion s.microsoft.com wrote in message
news:15******** *************** ***********@mic rosoft.com...
>I have recently migrated to VS.Net 2005, and I am struggling to do
something
very basic with the combo box. I want to manually loop through a data
table
and add both the display text and the value manually. The reason I cannot
bind the combo box to my data table is that there are more than one field
that I want to combine to be the display member. So what I had to do was
create yet another data table at run time (or an array list) and combine
the
columns in my new data table so it would display the way I want it to.
This
is much more code than simply lookping through my original data table and
adding the item and setting the value manually. I don't want to have to
do
this for every combo box in the application. is it possible to set the
value
member of a combo box item without binding it to a data source?

I also noticed that when I set the display member to a field that has a
space in it (i.e. [last name]) the value member displays.

Jun 21 '07 #2

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

Similar topics

2
8206
by: Terry Bickle | last post by:
Please forgive me for using the wrong term here or there. I'm an old Excel 4 macro guy who didn't convert to VB and I'm tinkering with an Access 2000 DB. I'm sure there is a simple Access 101 answer for this. I have a subform which the user selects an item description from a combo box from a table. I want to obtain the cost for the item...
8
18322
by: Lyn | last post by:
Hi, Can anyone tell me how the initial value displayed in Combo Box is determined when a form is opened? I am loading the dropdown from one field ("CategoryName") of a table, with "ORDER BY ". The values in the dropdown are loaded in the correct order, but the initial value is not the first row of the dropdown as I expected. The field...
1
11809
by: meganrobertson22 | last post by:
Hi Everyone- I am trying to use a simple macro to set the value of a combo box on a form, and I can't get it to work. I have a macro with 2 actions: OpenForm and SetValue. I can open my form, but I can't get the macro to set the value of a combo box on the form that opens. I don't need the macro to look up any values, I just want it to...
8
12070
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the combobox. What is the solution? Thank you in advance.
20
3670
by: MLH | last post by:
120 MyString = "How many copies of each letter do you need?" 150 MyVariant = InputBox(MyString, "How Many?", "3") If MyVariant = "2" Then MsgBox "MyVariant equals the string '2'" If MyVariant = 2 Then MsgBox "MyVariant also equals the value 2" 160 If MyVariant = "" Then HowManyCopies = 1 170 If Not IsNumeric(MyVariant) Then...
2
8653
by: shumaker | last post by:
I have a combobox that is very much like the one found in the RSS project here: http://msdn.microsoft.com/vstudio/express/visualCSharp/learning/ My projectNameComboBox basically is filled with a list of values from a table, and as the user selects values, a datagrid displays related records from another table because it is bound via FK...
3
2612
by: Dave | last post by:
I would like to have the word "Select" as the default option in a combo box that will retrieve its data from database. I also would like to have the ability to validate the combo box to ensure that the default option not used. This combo box is complex bounded. -- L. A. Jones
2
4494
by: =?Utf-8?B?UGFvbG8=?= | last post by:
Having problems with combo box Display Member and Value Member. Using a typed dataset I have the following: private void frmMain_Load(object sender, EventArgs e) { cmbxPayee.DisplayMember = dataSet.Payee.P_NameColumn.ToString(); cmbxPayee.ValueMember = dataSet.Payee.P_IdColumn.ToString(); cmbxPayee.DataSource = dataSet.Payee;
2
3524
by: Infog | last post by:
Using this code, the display member of the combo box is displaying the text "System.Data.DataViewManagerListItemTypeDescriptor". Huh??? The first block of code gets the data from the database, and works as far as I know. The second block of code sets the first value of the form, and does NOT work like I want it too. I commented out the line...
0
7526
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
7457
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
7723
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. ...
1
7483
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...
0
7817
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...
0
6051
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...
0
3504
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...
1
1949
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
1063
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.