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. C#
  4. ComboBoxes & DataTables

ComboBoxes & DataTables

Scheduled Pinned Locked Moved C#
helpquestion
3 Posts 3 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.
  • J Offline
    J Offline
    JDUK
    wrote on last edited by
    #1

    Ok i have a DataTable that has 2 columns: ID & Name I have populated a combo box from that data table like so ComboBox1.DataSource = XmlIn.Tables["Names"]; ComboBox1.DisplayMember = "Name"; Now when a user selects a name from the combobox and then clicks a button i need away to return the coresponding ID to that name. I have thought of using a DataView to scan for the name and return the relevent number but was sure there was a tidier way to return the ID value. Can any one help? Thank you.

    J G 2 Replies Last reply
    0
    • J JDUK

      Ok i have a DataTable that has 2 columns: ID & Name I have populated a combo box from that data table like so ComboBox1.DataSource = XmlIn.Tables["Names"]; ComboBox1.DisplayMember = "Name"; Now when a user selects a name from the combobox and then clicks a button i need away to return the coresponding ID to that name. I have thought of using a DataView to scan for the name and return the relevent number but was sure there was a tidier way to return the ID value. Can any one help? Thank you.

      J Offline
      J Offline
      Jon G
      wrote on last edited by
      #2

      set the ValueMember property of the control: ComboBox1.ValueMember = "ID"; ComboBox1.DisplayMember = "Name"; ComboBox1.DataSource = XmlIn.Tables["Names"]; Then, you can get the selected Value by using the SelectedValue property: ComboBox1.SelectedValue; Jon G www.Gizmocoder.com

      1 Reply Last reply
      0
      • J JDUK

        Ok i have a DataTable that has 2 columns: ID & Name I have populated a combo box from that data table like so ComboBox1.DataSource = XmlIn.Tables["Names"]; ComboBox1.DisplayMember = "Name"; Now when a user selects a name from the combobox and then clicks a button i need away to return the coresponding ID to that name. I have thought of using a DataView to scan for the name and return the relevent number but was sure there was a tidier way to return the ID value. Can any one help? Thank you.

        G Offline
        G Offline
        Gavin Jeffrey
        wrote on last edited by
        #3

        just add another line to you code after setting the displaymember - combobox1.ValueMember = XmlIn.Tables["ID"]; then to get the id you could do something like - combobox1.SelectedValue.toString() gavirj

        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