这个问题有两种方法 第一种是用DataGridview中自带的DataGridViewTextBoxColumn 控件,第二种是动态添加combobox控件
方法一:
首先 窗体上拖拽一个 DataGridview
然后在这个DataGridview中添加两列DataGridViewTextBoxColumn (第一列叫A,第二列叫B)
然后绑定A代码
A.DataSource = ds.Tables[0].DefaultView;
A.DisplayMember = "table_name";
A.ValueMember = "table_name";
((DataGridViewComboBoxColumn)dataGridView1.Columns[0]).DefaultCellStyle.NullValue = "--请选择--"; //默认值
其次是绑定B代码
//当前选中行的第二列赋值
((DataGridViewComboBoxCell)dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1]).DataSource = ds.Tables[0].DefaultView;
((DataGridViewComboBoxCell)dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[1]).DisplayMember = "comments";
((DataGridViewComboBoxCell)dataGridView1.Rows[dataGridVie