将数据绑定到DatagridCombobox [英] Bind Data to DatagridCombobox
本文介绍了将数据绑定到DatagridCombobox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HI朋友们,您能解释一下如何将数据绑定到DataGridViewComboboxColumn
吗.我尝试对此进行编码,但它给出了一条错误消息.这是我尝试进行的编码
HI friends, could you explain that how to bind data to DataGridViewComboboxColumn
.I tried coding for that but it gives an error message.Here is the coding which i tried
ds = new DataSet();
da = new SqlDataAdapter("select * from holiday", con);
da.Fill(ds, "holiday");
DataTable tab = ds.Tables[0];
MessageBox.Show(ds.Tables[0].Rows.Count.ToString());
int i = 0;
foreach (DataRow row in tab.Rows)
{
dataGridView1.Rows.Add();
//MessageBox.Show(row[0].ToString());
dataGridView1[0, 1].Value=row[0].ToString();
dataGridView1[1, i].Value = row[1].ToString();
dataGridView1[2,i].Value = row[2].ToString();
i++;
}
推荐答案
我认为为此目的使用键入的DataSet
会很容易.
您可以看一下这篇文章
用于从DataBase和使用反射将DataTable保存到数据库中 [ http://msdn.microsoft.com/en-us/library/system. windows.forms.datagridviewcomboboxcolumn.aspx [ ^ ]
I think it will be easy to use typedDataSet
s for this purpose.
You can take a look at this article
General purpose class to fill DataTable(s) from DataBase and to save DataTable(s) to DataBase using reflection[^]
for easily filling theDataTable
s from database and savingDataTable
s to database.
Then to bind theDataGridViewComboboxColumn
set theDataSource
property to yourDataTable
and
ValueMember
,DisplayMember
properties to field required in the table.
An example is given here
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.aspx[^]
这篇关于将数据绑定到DatagridCombobox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文