 |
| VS.NET 2002/2003 Discussions about the Visual Studio.NET programming environment, the 2002 (1.0) and 2003 (1.1).
** Please don't post code questions here **
For issues specific to a particular language in .NET, please see the other forum categories. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the VS.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

November 5th, 2003, 05:35 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Combo Boxes
When I try to set the value member of a combo box.
cmbCombo.valuemember = "fieldname"
The value that this is returning is the string "fieldname".
It is not actually returning the value that I expected --> "fieldID".
What am i doing wrong?
|
|

November 7th, 2003, 01:37 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
The ValueMember property isn't designed to be used in code. You probably have to give it an object of some type. I would use the DataValueField property instead.
Bill Sempf
Effective Visual Studio .NET
|
|

November 7th, 2003, 11:20 AM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Could you elaborate, please.
|
|

November 7th, 2003, 11:26 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Are you trying to set the VALUE of a combobox? Or are you trying to set the field name for the value property of the options when you databind it?
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 7th, 2003, 12:04 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have already flooded the combobox with the data that I need (FacilityName), this is the information that I want the user to see. Now I want the (FacilityID) to be with each FacilityName, with the FacilityID hidden. I need the FacilityID so I can write that back to SQL when a user chooses a FacilityName.
Hopefully this makes sense, if not let me know.
|
|

November 7th, 2003, 01:03 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
(Sorry for the repost, please ignore in email. Somehow I replied quoted instead of fixing something, then deleted both instead of just one.  )
Ah ok. I think what you are looking for is DisplayMember.
From the MSDN docs...
To bind a ComboBox or ListBox control- Set the DataSource property to a data source object. Possible data sources include a data table, a data view, a dataset, a data view manager, an array, or any class that implements the IList interface.
- Set the DisplayMember property to the name of a column in the data source object:
' Visual Basic
Private Sub BindComboBox()
ComboBox1.DataSource = DataSet1.Tables("Suppliers")
ComboBox1.DisplayMember = "ProductName"
End Sub
// C#
private void BindComboBox()
{
comboBox1.DataSource = dataSet1.Tables["Suppliers"];
comboBox1.DisplayMember = "ProductName";
}
Peter
------------------------------------------------------
Work smarter, not harder.
|
|

November 7th, 2003, 01:43 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I have no problem setting the DisplayMember (FacilityName), that works fine. What I need to do is set the ValueMember (FacilityID).
When I set the ValueMember
(cmbFacilityname.ValueMember = "FacilityID")
I set a text box and set the .text property to
txtFacilityID.text = cmbFacilityname.ValueMember
I am setting the txtFacilityID.text so I can see what ValueMember is being returned. Oddly enough, the value being returned is the string "FacilityID", not the actual integer "FacilityID".
It's almost like .NET thinks I want the ValueMember to be the string "FacilityID" instead of the integer "FacilityID".
I used the help and did exactly what it told me to do, but it still isn't working the way I want it to work.
|
|

November 7th, 2003, 04:45 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Ok, I follow you now I think. You are getting the right thing. The combo box is telling you what the ValueMember is (FacilityID).
The Items collection of a windows form combo box contains a collection of objects (unlike the listbox control of a web form) so you can actually access all the members of whatever object is in the collection.
So...
You have a couple options:
1. Cast comboBox.SelectedItem into the right object, then access the desired property.
2. Use comboBox.SelectedValue. This gets the value of the list item member specified by ValueMember.
Sorry it took so long to get an answer, I wasn't clear on what you were trying to do. It's been one of those days.
Peter
------------------------------------------------------
Work smarter, not harder.
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Combo Boxes |
nbuckwheat |
Access |
1 |
January 15th, 2006 09:26 AM |
| 3 combo boxes |
ttkt |
Beginning PHP |
0 |
July 2nd, 2005 02:20 PM |
| Combo Boxes |
tjs206 |
VB Databases Basics |
2 |
December 10th, 2003 05:20 PM |
| combo boxes |
damnnono_86 |
Access |
2 |
October 15th, 2003 09:00 PM |
| Combo Boxes |
Louisa |
Beginning VB 6 |
2 |
September 10th, 2003 09:26 AM |
|
 |