Results 1 to 6 of 6

Thread: [RESOLVED] [2005] combobox databinding

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] [2005] combobox databinding

    im trying to bind dataset at runtime to combobox with the valuemember and displaymember column assign. im playing this code

    vb Code:
    1. ComboBox1.DataSource = ds.Tables(0)
    2.         ComboBox1.ValueMember = "pk_clientID"
    3.         ComboBox1.DisplayMember = "clientname"

    to make the name appear in the combobox item list and on the other hand the ID will be use for details referencing.

    tnx

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

    Re: [2005] combobox databinding

    Do you have a question?
    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
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [2005] combobox databinding

    oops why did i post that unfinish. anyway here the remaining part:

    vb Code:
    1. Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
    2.         MessageBox.Show(ComboBox1.ValueMember)
    3.     End Sub

    and this return the string "pk_clientID" regardless of what ive selected in the combobox item its return the same value.
    Last edited by jlbantang; Jul 18th, 2008 at 10:59 AM.

  4. #4
    Frenzied Member dolot's Avatar
    Join Date
    Nov 2007
    Location
    Ancient City, U.S.
    Posts
    1,254

    Re: [2005] combobox databinding


    Yes, the valuemember only gets/sets the field in the datasource to use for the value property. To get the value that is selected use combobox1.selectedvalue.
    I always add to the reputation of those whose posts are helpful, and even occasionally to those whose posts aren't helpful but who obviously put forth a valiant effort. That is, when the system will allow it.
    My war with a browser-redirect trojan

  5. #5
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: [2005] combobox databinding

    i think you are looking for

    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged        
    
    MessageBox.Show(ComboBox1.SelectedValue)    
    
    End Sub
    __________________
    Rate the posts that helped you

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Re: [2005] combobox databinding

    perfect!

    tnx

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