c#中怎样绑定datagridview中的单元格
1个回答
展开全部
DatagridViewComboxColumn
cmbox
=
Datagridview.Columns["COmbox控件的Name"]
as
DatagridViewComboxColumn
;
cmbox.DataSource
=
下框的数据源;
cmbox.DataPropertyName=
datagrid的数据源的要绑定的列;
cmbox.d...Member="下拉框显示的TEXT";
cmbox.ValueMember="隐藏的值";
DataGridViewComboBoxColumn
csex
=
new
DataGridViewComboBoxColumn();
csex.DataPropertyName
=
"sSex";
csex.HeaderText
=
"性别";
DataTable
dt
=
new
DataTable();
dt.Columns.Add("sexname");
dt.Columns.Add("sexvalue");
DataRow
dr
=
dt.NewRow();
dr[0]
=
"男";
dr[1]
=
"1";
dt.Rows.Add(dr);
DataRow
dr1
=
dt.NewRow();
dr1[0]
=
"女";
dr1[1]
=
"2";
dt.Rows.Add(dr1);
csex.DataSource
=
dt;
csex.ValueMember
=
"sexvalue";
csex.DisplayMember
=
"sexname";
this.datagridview1.Columns.Add(csex);
cmbox
=
Datagridview.Columns["COmbox控件的Name"]
as
DatagridViewComboxColumn
;
cmbox.DataSource
=
下框的数据源;
cmbox.DataPropertyName=
datagrid的数据源的要绑定的列;
cmbox.d...Member="下拉框显示的TEXT";
cmbox.ValueMember="隐藏的值";
DataGridViewComboBoxColumn
csex
=
new
DataGridViewComboBoxColumn();
csex.DataPropertyName
=
"sSex";
csex.HeaderText
=
"性别";
DataTable
dt
=
new
DataTable();
dt.Columns.Add("sexname");
dt.Columns.Add("sexvalue");
DataRow
dr
=
dt.NewRow();
dr[0]
=
"男";
dr[1]
=
"1";
dt.Rows.Add(dr);
DataRow
dr1
=
dt.NewRow();
dr1[0]
=
"女";
dr1[1]
=
"2";
dt.Rows.Add(dr1);
csex.DataSource
=
dt;
csex.ValueMember
=
"sexvalue";
csex.DisplayMember
=
"sexname";
this.datagridview1.Columns.Add(csex);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询