日期:2014-05-19  浏览次数:20980 次

关于datagridview 数据邦定的问题
请教,如果大家新建一DataSet,再把这个数据源邦定DataGridView,数据就是自动出现在datagridview里,但是如果这里面含有DataGridViewcomboBoxcolumn或checkboxcolumn列的话,各位大侠是怎么实现的..
        先谢了..

------解决方案--------------------
使用了DataGridView中的DataGridViewComboBoxColumn的列类型.
通过如下形式给该列( 设为:dgvcbcolumn)设置绑定数据源
DataTable table = new DataTable( "tb_sex ");
DataColumn column;
DataRow row;

column = new DataColumn();
column.DataType = System.Type.GetType( "System.Int32 ");
column.ColumnName = "id ";
table.Columns.Add(column);

column = new DataColumn();
column.DataType = System.Type.GetType( "System.String ");
column.ColumnName = "name ";
table.Columns.Add(column);

row = table.NewRow();
row[ "id "] = 0;
row[ "name "] = "女 ";
table.Rows.Add(row);

row = table.NewRow();
row[ "id "] = 1;
row[ "name "] = "男 ";
table.Rows.Add(row);

this.dgvcbcolumn.DataSource = table;
this.dgvcbcolumn.DisplayMember = "name ";
this.dgvcbcolumn.ValueMember = "id ";