Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 5th, 2003, 05:35 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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?
Reply With Quote
  #2 (permalink)  
Old November 7th, 2003, 01:37 AM
Authorized User
 
Join Date: Jun 2003
Location: Grove City, Ohio, USA.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to sempf
Default


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
Reply With Quote
  #3 (permalink)  
Old November 7th, 2003, 11:20 AM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Could you elaborate, please.

Reply With Quote
  #4 (permalink)  
Old November 7th, 2003, 11:26 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
Reply With Quote
  #5 (permalink)  
Old November 7th, 2003, 12:04 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #6 (permalink)  
Old November 7th, 2003, 01:03 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

(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.
Reply With Quote
  #7 (permalink)  
Old November 7th, 2003, 01:43 PM
Registered User
 
Join Date: Nov 2003
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.

Reply With Quote
  #8 (permalink)  
Old November 7th, 2003, 04:45 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:30 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.