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. Databound ComboBox Selection Problems

Databound ComboBox Selection Problems

Scheduled Pinned Locked Moved C#
databasehelp
1 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.
  • G Offline
    G Offline
    Glenn E Lanier II
    wrote on last edited by
    #1

    I am displaying a ComboBox that hopefully contains the contents of a database table (a lookup of sorts). When the form loads, the ComboBox contains the correct values, all sorted. :) However, when I try to select a value programitically, I can't (well, I can't select the correct one). :( I create a dataset: DataSet dsTitles = new DataSet("Titles"); SqlCommand tableCommand = new SqlCommand(); tableCommand.CommandText = "select TitleID, TitleDisplayText FROM tblTitles WHERE TitleHidden <> 1"; SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = tableCommand; adapter.Fill(dsTitles, "Titles"); I then bind the dataset to the ComboBox: comboBoxTitle.BeginUpdate(); comboBoxTitle.DataSource = db.DataSetTitles.Tables["Titles"]; comboBoxTitle.DisplayMember = "TitleDisplayText"; comboBoxTitle.ValueMember = "TitleID"; comboBoxTitle.EndUpdate(); So far, all is well. However, I can't seem to select the correct item. I've tried: comboBoxTitle.SelectedValue = 2; Console.WriteLine("Current Title Index: {0} Text: {1} Combo Index: {2} Value: {3} Text: {4}", 2, db.LookupValueTitle(2), comboBoxTitle.SelectedIndex, comboBoxTitle.SelectedValue); TitleID of 2 matches TitleDisplayText of Mr, but nothing is visibily selected.

    Current Title Index: 2 Text: Mr Combo Index: 0 Value: 2 Text:

    is what gets logged. Any help would be appreciated. --G :confused:

    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