Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. combo box item values - Possible?

combo box item values - Possible?

Scheduled Pinned Locked Moved Visual Basic
helpquestion
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cwayman
    wrote on last edited by
    #1

    hey, i am trying to assign values to my combo box items. I thought that as you add an item to a combo box you could also just add a value. I am having great trouble doing this. i have a datatable with a 'name' and 'id' column. i want the combo box to display the name but when it is selected to get the id. i currently have the following code

    cmboConnections.DisplayMember = "name"

        For i = 0 To connectionTable.Rows.Count - 1
    
            If Not connectionTable.Rows(i).Item("name") Is Nothing Then
    
                cmboConnections.Items.Add(connectionTable.Rows(i).Item("name"))
                cmboConnections.ValueMember = connectionTable.Rows(i).Item("ID")
    
            End If
        Next
    

    I am unable to find any property wher you can just combobox.SelectedItem.Value or combobox.Item(X).Value. Is there any way to set a value of a item in a combo box? Thanks for your help Chris

    C 1 Reply Last reply
    0
    • C cwayman

      hey, i am trying to assign values to my combo box items. I thought that as you add an item to a combo box you could also just add a value. I am having great trouble doing this. i have a datatable with a 'name' and 'id' column. i want the combo box to display the name but when it is selected to get the id. i currently have the following code

      cmboConnections.DisplayMember = "name"

          For i = 0 To connectionTable.Rows.Count - 1
      
              If Not connectionTable.Rows(i).Item("name") Is Nothing Then
      
                  cmboConnections.Items.Add(connectionTable.Rows(i).Item("name"))
                  cmboConnections.ValueMember = connectionTable.Rows(i).Item("ID")
      
              End If
          Next
      

      I am unable to find any property wher you can just combobox.SelectedItem.Value or combobox.Item(X).Value. Is there any way to set a value of a item in a combo box? Thanks for your help Chris

      C Offline
      C Offline
      cwayman
      wrote on last edited by
      #2

      I am now using a datatable cmboConnections.DataSource = connectionTable cmboConnections.DisplayMember = "name" cmboConnections.ValueMember = "ID" Which populates my combobox but i have no way of retrieving the Valuemember from the selectedIndexchanged event. Does anyone no how to get the ValueMember from a selected item? I have tried using the SelectedIndexChanged Event but the combobox.SelectedValue is a datarow and cannot be converted to string apparently? Any suggestions this is quite urgent Thanks for your help Chris

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups