none
How to view selected item from combox into textbox?

    Question

  •  string constr = @"Data Source=192.168.*.*; Database=wsditsupport; User ID=**; Password=**";
            public Form7()
            {
                InitializeComponent();
                
                MySqlConnection cn = new MySqlConnection(constr);
                string value = "SELECT passover_info FROM probing_production";
                MySqlDataAdapter adp = new MySqlDataAdapter(value, cn);
                DataTable dt = new DataTable();
                adp.Fill(dt);
                comboBox1.DataSource = dt;
                comboBox1.DisplayMember = "passover_info";
                cn.Close();
            }
    
            private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                if (comboBox1.SelectedIndex == -1)
                {
                    textBox1.Text = string.Empty;
                }
                else
                {
                    textBox1.Text = comboBox1.SelectedItem.ToString();
                }
            }

    When I try run debug, This is the result I get into textbox >>> "System.Data.DataRowView"

    Loginthiren

    Thursday, June 23, 2016 6:46 AM

Answers

  • else
               {
                   textBox1.Text = ((DataRowView)comboBox1.SelectedItem)["passover_info"].ToString();
               }

    This is the solution that I try and fix it.

    Loginthiren

    • Marked as answer by Thiren Monday, June 27, 2016 9:58 AM
    Thursday, June 23, 2016 7:25 AM

All replies