Results 1 to 3 of 3

Thread: [RESOLVED] ComboBox (Display, Value)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    207

    Resolved [RESOLVED] ComboBox (Display, Value)

    Hi,

    I have a combo box where I populate manually from the database and using datareader.

    From memory, in VB6 you could add the display value and the actual value, but in .NET there is not this option?

    Anyway to get around this?

    Thanks.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: ComboBox (Display, Value)

    Don't populate the ComboBox manually from the DataReader. Use the DataReader to populate a DataTable and then bind that to the ComboBox. Problem solved.
    vb.net Code:
    1. Dim table As New DataTable
    2.  
    3. table.Load(reader)
    4. reader.Close()
    5.  
    6. myComboBox.DisplayMember = "Name"
    7. myComboBox.ValueMember = "ID"
    8. myComboBox.DataSource = table
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Posts
    207

    Re: ComboBox (Display, Value)

    Legend. Worked a treat. Thanks for that, and thank you for the quick response.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width