请问各位,将combox嵌入到datagridview中,如何让combox的内容为数据库取出的列值?
DataTable dtSex = new DataTable();
dtSex.Columns.Add("Value");
dtSex.Columns.Add("Name");
DataRow drSex;
drSex = dtSex.NewRow();
drSex[0] = "1";
drSex[1] = "男";
dtSex.Rows.Add(drSex);
drSex = dtSex.NewRow();
drSex[0] = "0";
drSex[1] = "女";
dtSex.Rows.Add(drSex);
cbx.ValueMember = "Value";
cbx.DisplayMember = "Name";
cbx.DataSource = dtSex;
cbx.DropDownStyle = ComboBoxStyle.DropDownList;
这个应该怎么变呢?
------解决方案--------------------datagridviewcomboxColumn的名称是Column几?假设为i
Columni.Items.Addrange(new object []{})
其他老大有什么更好的办法没?
------解决方案--------------------
http://bbs.csdn.net/topics/390519666
看看这个对你有帮助没。
------解决方案--------------------
DataTable dt1 = dgvcbdata();
DataGridViewComboBoxColumn cmb = dataGridView1.Columns[1] as DataGridViewComboBoxColumn;
cmb.DataSource = dgvcbdata();
cmb.DataPropertyName = dt1.Columns[0].ColumnName;
cmb.ValueMember = dt1.Columns[0].ColumnName;
dataGridView1.DataSource = dgvdata();
------解决方案--------------------combox1.Items.Clear();
DataTable dt = get_datatable(); //get_datat