将数据绑定到组合框. [英] Binding Data to combo box.

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

问题描述

我将数据绑定到组合框.我正在检索数据库的表名并尝试填充它.当我在gridview中填充它时,它的工作正常.但是当我尝试相同的组合框时,它不起作用.

我使用的代码如下

I am binding data to a combp box .I am retrieveing table name of a database and trying to populate it.When i populate it in gridview its working fine.But when i try the same for combo box its not working.

The code i used is as follows

string con = "Data Source=..\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";
sda = new SqlDataAdapter("select name from sysobjects where xtype='U'", con);
SqlCommandBuilder sc1 = new SqlCommandBuilder(sda);
DataTable db1 = new DataTable();
sda.Fill(db1);
bd1.DataSource = db1;
dataGridView1.DataSource = bd1;
comboBox1.DataSource = bd1;



当我将其绑定到网格视图时,它会向我显示表名,但对于组合框,它会将值返回为System.Data.DataRowViews



when i bind it to grid view it shows me the table names,but for combo box it returning the values as System.Data.DataRowViews

What should be done to correct the error.

推荐答案

您需要添加DisplayMember和Valuemember.

You need to add DisplayMember and Valuemember.

comboBox1.DisplayMember = "name";
               comboBox1.ValueMember = "name";



希望对您有所帮助,
Theingi Win



Hope be helpful,
Theingi Win


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

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