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. Database & SysAdmin
  3. Database
  4. Databound ComboBox Selection Problems

Databound ComboBox Selection Problems

Scheduled Pinned Locked Moved Database
databasehelp
4 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.
  • 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:

    S M 2 Replies Last reply
    0
    • G Glenn E Lanier II

      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:

      S Offline
      S Offline
      sreejith ss nair
      wrote on last edited by
      #2

      Try to use comboBoxTitle.Text insted of comboBoxTitle.SelectedValue:-D Sreejith Nair [ My Articles ]

      G 1 Reply Last reply
      0
      • G Glenn E Lanier II

        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:

        M Offline
        M Offline
        miah alom
        wrote on last edited by
        #3

        Sreejith's solution should work. Also keep in mind http://support.microsoft.com/kb/327244

        1 Reply Last reply
        0
        • S sreejith ss nair

          Try to use comboBoxTitle.Text insted of comboBoxTitle.SelectedValue:-D Sreejith Nair [ My Articles ]

          G Offline
          G Offline
          Glenn E Lanier II
          wrote on last edited by
          #4

          Thanks. Tried that -- didn't work. I fixed it by removing the comboBox from the form, then adding it back. Don't understand, but problem solved.

          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