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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. combobox.datasource question

combobox.datasource question

Scheduled Pinned Locked Moved C#
question
4 Posts 2 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.
  • U Offline
    U Offline
    udikantz
    wrote on last edited by
    #1

    hello and thanks for reading this: im having problems in getting the selected item(the text) from a combobox when using the .datasource property. i got something like this: this.comboBox_add_to_group.DataSource = sku_ds.Tables[0]; this.comboBox_add_to_group.ValueMember = "SKU"; this.comboBox_add_to_group.DisplayMember = "SKU"; and im trying to make an event that any time the user changes the selected item within the combobox i would print to the console THE TEXT of the selected item. but evrything i did return stuff like "system.data.....()" so my question is is there a formal way to get the string that i see in the combobox when using the .datasource property , if so , how is it done? thanks

    Net

    M 1 Reply Last reply
    0
    • U udikantz

      hello and thanks for reading this: im having problems in getting the selected item(the text) from a combobox when using the .datasource property. i got something like this: this.comboBox_add_to_group.DataSource = sku_ds.Tables[0]; this.comboBox_add_to_group.ValueMember = "SKU"; this.comboBox_add_to_group.DisplayMember = "SKU"; and im trying to make an event that any time the user changes the selected item within the combobox i would print to the console THE TEXT of the selected item. but evrything i did return stuff like "system.data.....()" so my question is is there a formal way to get the string that i see in the combobox when using the .datasource property , if so , how is it done? thanks

      Net

      M Offline
      M Offline
      mihirhp
      wrote on last edited by
      #2

      Hello... Try this one..... private void Form1_Load(object sender, EventArgs e) { DataSet ds = GetDataSet(); comboBox1.DataSource = ds.Tables[0]; comboBox1.ValueMember = ds.Tables[0].Columns["empName"].ToString(); comboBox1.DisplayMember = ds.Tables[0].Columns["empID"].ToString(); } private DataSet GetDataSet() { SqlConnection conn = new SqlConnection(@"Data Source = PC6; Initial Catalog = Test; User Id = diipluser6; Password = willy007"); SqlCommand cmd = new SqlCommand("Select * From tblEmp", conn); SqlDataAdapter adt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adt.Fill(ds); conn.Open(); conn.Close(); return ds; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = comboBox1.SelectedValue.ToString(); //MessageBox.Show(comboBox1.SelectedValue.ToString()); }

      U 1 Reply Last reply
      0
      • M mihirhp

        Hello... Try this one..... private void Form1_Load(object sender, EventArgs e) { DataSet ds = GetDataSet(); comboBox1.DataSource = ds.Tables[0]; comboBox1.ValueMember = ds.Tables[0].Columns["empName"].ToString(); comboBox1.DisplayMember = ds.Tables[0].Columns["empID"].ToString(); } private DataSet GetDataSet() { SqlConnection conn = new SqlConnection(@"Data Source = PC6; Initial Catalog = Test; User Id = diipluser6; Password = willy007"); SqlCommand cmd = new SqlCommand("Select * From tblEmp", conn); SqlDataAdapter adt = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); adt.Fill(ds); conn.Open(); conn.Close(); return ds; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { textBox1.Text = comboBox1.SelectedValue.ToString(); //MessageBox.Show(comboBox1.SelectedValue.ToString()); }

        U Offline
        U Offline
        udikantz
        wrote on last edited by
        #3

        thanks for the reply , this line: comboBox1.SelectedValue.ToString(); return this string for me: System.Data.DataRowView

        Net

        M 1 Reply Last reply
        0
        • U udikantz

          thanks for the reply , this line: comboBox1.SelectedValue.ToString(); return this string for me: System.Data.DataRowView

          Net

          M Offline
          M Offline
          mihirhp
          wrote on last edited by
          #4

          If u Put all things as I shown then it wont show the problem...... Try it again is I shown....

          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