求助一个COMBOBOX问题!
(只有这么多分了,大家就当是帮帮忙咯)
WINFORM中,将DATAGRID中的字段名显示到COMBOBOX的下拉菜单中。
如DATAGRID表中:
A B C D
1 2 3 4
显示到COMBOBOX中,显示为
A
B
C
D
我的程序为:
int index = this.dg.CurrentRowIndex;
if(index < 0)
return;
comboBox1 ??= (this.dg.DataSource as//这段有错,不知怎么写
DataSet).Tables[0].Rows[index];
for(int i=0;i<comboBox1.Items.Count;i++)
{
this.comboBox1.Items[i] = (this.dg.DataSource as DataSet).Tables[0].Columns[i].ColumnName;
}
求高手帮修改下,或者弄段完整的代码来看看。