Results 1 to 5 of 5

Thread: Combo display & value [RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Combo display & value [RESOLVED]

    Hi All

    Ive got a combo box which is being filled by a dataset i want to show the text value from one column but when a user makes their selection i want to pass over the datasets record Id rather than the text value (How is this done)

    Heres the vb code for filling the combo

    VB Code:
    1. Private Sub Designer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim objData As New NewForestMortgagesAPP.DesignerDI.GetDI
    3.         Me.cboLetter.DisplayMember = "LetterName"
    4.         Me.cboLetter.DataSource = objData.GetDataSet.Tables(0)
    5.     End Sub

    I just wana know the correct way of doing this ?

    Many Thanks
    Last edited by carlblanchard; Jan 29th, 2004 at 11:41 AM.
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    try something like this
    VB Code:
    1. Dim objData As New NewForestMortgagesAPP.DesignerDI.GetDI
    2.        
    3. Me.cboLetter.DataSource = objData.GetDataSet.Tables(0)
    4. Me.cboLetter.DataValueField = "RecordId"
    5. Me.cboLetter.DataTextField = "LetterName"
    6. Me.cboLetter.DataBind()
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    is that for asp.net because theres no such property of DataValueField within a win form combo box
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    You would do like Memnoch1207 showed only the Property should be "ValueMember" and then to get the value use the SelectedValue property instead of the Text property.

  5. #5

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    Yep i done it with ValueMember = "ColumnName"
    I was trying to get the value by using ValueMember as well (when its simply SelectedValue that returns the correct ID )

    I must say ( this method of binding to control ) is absolutly wicked.

    My Code is looking cleaner and more understandable every single day Thanks All
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

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