datagridview有2列,1列是省份名称,1列是省下面所有城市的名称。
DataGridViewTextBoxColumn DataGridViewComboBoxColumn
我就不知道DataGridViewComboBoxColumn这个如何绑定?因为每一行的数据源都不一样。
多谢!
8 个解决方案
#1
郁闷...
#2
....
#3
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
dgvc.HeaderText = "ID";
dgvc.Name = "ID";
dgvc.Items.AddRange(new string[] { "1", "2", "3" });
dataGridView1.Columns.Insert(0, dgvc);
遍历设置数据源
dgvc.HeaderText = "ID";
dgvc.Name = "ID";
dgvc.Items.AddRange(new string[] { "1", "2", "3" });
dataGridView1.Columns.Insert(0, dgvc);
遍历设置数据源
#4
d_dataGridView.DataSource = l_listObject; //实体列表
d_dataGridView.Columns.Clear();
//创建文本框
dgv.AutoGenerateColumns = false;
DataGridViewTextBoxColumn d_objTextBox = new DataGridViewTextBoxColumn();
d_objTextBox.DataPropertyName = "Name";
d_objTextBox.HeaderText = headerText;
d_objTextBox.Name = "Name";
dgv.Columns.AddRange(new DataGridViewColumn[] { d_objTextBox });
//创建下拉框
DataGridViewComboBoxColumn d_objComboBox = new DataGridViewComboBoxColumn();
d_objComboBox.DataSource = ?;
d_objComboBox.HeaderText = headerText;
d_objComboBox.Name = "author";
dgv.Columns.AddRange(new DataGridViewColumn[] { d_objComboBox });
数据源咋样给?该如何遍历?
#5
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
dgvc.Width = 90;
dgvc.Name = "CBLX";
dgvc.HeaderText = "类型";
//conn.BindData(lxSql, dgvc);
dgvc.DataSource = dt;
dgvc.DataPropertyName = "编辑列上的字段";
dgvc.DisplayMember = "数据库省份对应的字段";
dgvc.ValueMember = "数据存的字段";
dgvKfxx.Columns.Insert(1, dgvc);
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
cb.Width = 90;
cb.Name = "CBLX";
cb.HeaderText = "类型";
//conn.BindData(lxSql, cb);
cb.DataSource = dt;
cb.DataPropertyName = "编辑列上的字段";
cb.DisplayMember = "数据库城市对应的字段";
cb.ValueMember = "数据存的字段";
//dgvKfxx.Columns.Add(cb);
dgvKfxx.Columns.Insert(2, cb);
LZ照样子就OK啦
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
dgvc.Width = 90;
dgvc.Name = "CBLX";
dgvc.HeaderText = "类型";
//conn.BindData(lxSql, dgvc);
dgvc.DataSource = dt;
dgvc.DataPropertyName = "编辑列上的字段";
dgvc.DisplayMember = "数据库省份对应的字段";
dgvc.ValueMember = "数据存的字段";
dgvKfxx.Columns.Insert(1, dgvc);
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
cb.Width = 90;
cb.Name = "CBLX";
cb.HeaderText = "类型";
//conn.BindData(lxSql, cb);
cb.DataSource = dt;
cb.DataPropertyName = "编辑列上的字段";
cb.DisplayMember = "数据库城市对应的字段";
cb.ValueMember = "数据存的字段";
//dgvKfxx.Columns.Add(cb);
dgvKfxx.Columns.Insert(2, cb);
LZ照样子就OK啦
#6
我那个数据源是好多xml文件里面拼接起来一些数据,我弄到一个实体类里,然后形成一个集合。
还不如自己写个控件方便,不过还是想搞明白这个。
还不如自己写个控件方便,不过还是想搞明白这个。
#7
在顶下
#8
还有没有?
#1
郁闷...
#2
....
#3
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
dgvc.HeaderText = "ID";
dgvc.Name = "ID";
dgvc.Items.AddRange(new string[] { "1", "2", "3" });
dataGridView1.Columns.Insert(0, dgvc);
遍历设置数据源
dgvc.HeaderText = "ID";
dgvc.Name = "ID";
dgvc.Items.AddRange(new string[] { "1", "2", "3" });
dataGridView1.Columns.Insert(0, dgvc);
遍历设置数据源
#4
d_dataGridView.DataSource = l_listObject; //实体列表
d_dataGridView.Columns.Clear();
//创建文本框
dgv.AutoGenerateColumns = false;
DataGridViewTextBoxColumn d_objTextBox = new DataGridViewTextBoxColumn();
d_objTextBox.DataPropertyName = "Name";
d_objTextBox.HeaderText = headerText;
d_objTextBox.Name = "Name";
dgv.Columns.AddRange(new DataGridViewColumn[] { d_objTextBox });
//创建下拉框
DataGridViewComboBoxColumn d_objComboBox = new DataGridViewComboBoxColumn();
d_objComboBox.DataSource = ?;
d_objComboBox.HeaderText = headerText;
d_objComboBox.Name = "author";
dgv.Columns.AddRange(new DataGridViewColumn[] { d_objComboBox });
数据源咋样给?该如何遍历?
#5
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
dgvc.Width = 90;
dgvc.Name = "CBLX";
dgvc.HeaderText = "类型";
//conn.BindData(lxSql, dgvc);
dgvc.DataSource = dt;
dgvc.DataPropertyName = "编辑列上的字段";
dgvc.DisplayMember = "数据库省份对应的字段";
dgvc.ValueMember = "数据存的字段";
dgvKfxx.Columns.Insert(1, dgvc);
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
cb.Width = 90;
cb.Name = "CBLX";
cb.HeaderText = "类型";
//conn.BindData(lxSql, cb);
cb.DataSource = dt;
cb.DataPropertyName = "编辑列上的字段";
cb.DisplayMember = "数据库城市对应的字段";
cb.ValueMember = "数据存的字段";
//dgvKfxx.Columns.Add(cb);
dgvKfxx.Columns.Insert(2, cb);
LZ照样子就OK啦
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
dgvc.Width = 90;
dgvc.Name = "CBLX";
dgvc.HeaderText = "类型";
//conn.BindData(lxSql, dgvc);
dgvc.DataSource = dt;
dgvc.DataPropertyName = "编辑列上的字段";
dgvc.DisplayMember = "数据库省份对应的字段";
dgvc.ValueMember = "数据存的字段";
dgvKfxx.Columns.Insert(1, dgvc);
String lxSql = "select 城市 from KFLX";
datasetLX.Clear();
Adapter1 = conn.DataGridViewBind(lxSql);
Adapter1.Fill(datasetLX);
DataTable dt = datasetLX.Tables[0];
cb.Width = 90;
cb.Name = "CBLX";
cb.HeaderText = "类型";
//conn.BindData(lxSql, cb);
cb.DataSource = dt;
cb.DataPropertyName = "编辑列上的字段";
cb.DisplayMember = "数据库城市对应的字段";
cb.ValueMember = "数据存的字段";
//dgvKfxx.Columns.Add(cb);
dgvKfxx.Columns.Insert(2, cb);
LZ照样子就OK啦
#6
我那个数据源是好多xml文件里面拼接起来一些数据,我弄到一个实体类里,然后形成一个集合。
还不如自己写个控件方便,不过还是想搞明白这个。
还不如自己写个控件方便,不过还是想搞明白这个。
#7
在顶下
#8
还有没有?