求助一个COMBOBOX问题!

yqx13845057137 2007-07-01 12:15:28
(只有这么多分了,大家就当是帮帮忙咯)

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;
}
求高手帮修改下,或者弄段完整的代码来看看。
...全文
145 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
casablancaliu 2007-07-01
  • 打赏
  • 举报
回复
MARK
pfa2008 2007-07-01
  • 打赏
  • 举报
回复
for(int i=0;i<datagird.Columns.Count;i++)
{
this.comboBox1.Items.Add(datagird.Columns[i].HeadText);
}
intotheland 2007-07-01
  • 打赏
  • 举报
回复
int index = this.dg.CurrentRowIndex;
if(index < 0)
return;

for(int i=0;i<comboBox1.Items.Count;i++)
{
this.comboBox1.Items.Add(this.dg.DataSource as DataSet).Tables[0].Columns[i].ColumnName);
}

combobox.items.add();//添加选项

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧