本文介绍了如何从combox查看选定项目到文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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();
           }
       }
   }





我尝试过:



当我尝试运行调试时,这是我进入文本框的结果>>> System.Data.DataRowView



What I have tried:

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

推荐答案

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


这篇关于如何从combox查看选定项目到文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:10