Results 1 to 2 of 2

Thread: combobox and ojbects...

  1. #1
    aussierules is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jul 2012
    Posts
    1
    Reputation
    0

    combobox and ojbects...

    Hi,
    I have a combobox where I have added a number of objects :

    Dim objOp4a AsNewclsObjectobjOp4a.ID = 0
    objOp4a.Name ="NONE"
    cboConfig.Items.Add(objOp4a)

    Dim objOp4 AsNewclsObject
    objOp4.ID = 1
    objOp4.Name = "Put Bench"
    cboConfig.Items.Add(objOp4)

    Dim objOp5 AsNewclsObject
    objOp5.ID = 8
    objOp5.Name = "Sort Bench"
    cboConfig.Items.Add(objOp5)


    I now need to set the combobox (using vb.net code) to set its item to be the Sort bench text, but I only have the ID (8) to work with.

    Thanks

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    11,358
    Reputation
    1544
    Instead of adding the items directly to the ComboBox, put them into an array or collection and then bind that to the ComboBox:
    With myComboBox
    .DisplayMember = "Name"
    .ValueMemebr = "ID"
    .DataSource = myList
    End With
    You can then select an item by ID by assigning the desired value to the SelectedValue property of the ComboBox.

Bookmarks

Posting Permissions

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