如何将数据绑定到Windows窗体中的组合框 [英] how to bind data to a combobox in windows form

查看:75
本文介绍了如何将数据绑定到Windows窗体中的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我有这样的申请。



我想要的根据选定的组合框值过滤表单。 


在过滤器按钮中我编写了以下代码:


  if(sqlcon.State == System.Data.ConnectionState.Closed)

                 sqlcon.Open();

            DataTable dtb1 = new DataTable();

            SqlDataAdapter sqlda = new SqlDataAdapter();

          //  INT  internegerätnummer=(comboBox1.Text ==""?0:Convert.ToInt32(comboBox1.Text));

        &NBSP ; //  string Typ = comboBox2.Text;

            Int64 fabrikatnummer = Convert.ToInt64(comboBox3.Text);

        / *   日期时间ausgabedatum = Convert.ToDateTime(comboBox4.Text,System.Globalization.CultureInfo.GetCultureInfo(QUOT;喜-IN")DateTimeFormat);

            日期时间rückgabedatum= Convert.ToDateTime(comboBox5.Text,System.Globalization.CultureInfo.GetCultureInfo(QUOT;喜-IN")DateTimeFormat。); * /

         //    string Bemerkung = comboBox6.Text;

        //    string verwalter = comboBox7.Text;

解决方案

Hi mina,


>> ;但问题是当我从组合框中选择一个值,在clikcing on filter之前我有system.data.datarow用于其他组合框。你有任何提示可以帮助我吗?


我担心你需要提供有关错误信息的更多细节,什么是"有系统"其他组合框的.data.datarow"?我猜你遇到了一个错误,对吗?它是否命名为" System.Data.DataRowView "?如果是的话,恐怕
你 需要结合数据源 和 设置 'DisplayMember' 和 'ValueMember' 在Form_Load事件的组合框:


<预类= "prettyprint"> this.comboBox1.DisplayMember =" ..." ;;
this.comboBox1.ValueMember =" ..." ;;
this.comboBox1.DataSource = yourDataSource;

参考:
System.Data.DataRowView错误


问候,


Frankie


Hello,

i have an application like this.

i want to filter the form based on the selected value of combo boxes. 

in filter button i wrote the following code:

 if (sqlcon.State == System.Data.ConnectionState.Closed)
                sqlcon.Open();
            DataTable dtb1 = new DataTable();
            SqlDataAdapter sqlda = new SqlDataAdapter();
          //  int  internegerätnummer = ( comboBox1.Text == "" ? 0 : Convert.ToInt32(comboBox1.Text));
          //  string Typ = comboBox2.Text;
            Int64 fabrikatnummer = Convert.ToInt64 (comboBox3.Text);
        /*    DateTime ausgabedatum = Convert.ToDateTime(comboBox4.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
            DateTime rückgabedatum = Convert.ToDateTime(comboBox5.Text, System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);*/
        //    string Bemerkung = comboBox6.Text;
        //    string verwalter = comboBox7.Text;

解决方案

Hi mina,

>>but the problem is when i select a value from a combo box, before clikcing on filter i have system.data.datarow for other combo boxes. do you have any tips to help me please?

I'm afraid you need to provide more details about the error message, what is "have system.data.datarow for other combo boxes"? I guess you have encountered an error, right? Is it named "System.Data.DataRowView"? If so, I'm afraid you need to bind data source and set the 'DisplayMember' and 'ValueMember' for the comboBox in the Form_Load event:

this.comboBox1.DisplayMember = "...";
this.comboBox1.ValueMember = "...";
this.comboBox1.DataSource = yourDataSource;

Refer: System.Data.DataRowView error

Regards,

Frankie


这篇关于如何将数据绑定到Windows窗体中的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆