一:DatagridviewComboBox 选定索引更改时更改 DatagridviewTextBox 文本内容
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1 && e.Control is ComboBox)
{
ComboBox comboBox = e.Control as ComboBox;
comboBox.SelectedIndexChanged += LastColumnComboSelectionChanged;
}
}
private void LastColumnComboSelectionChanged(object sender, EventArgs e)
{
var currentcell = dataGridView1.CurrentCellAddress;
var sendingCB = sender as DataGridViewComboBoxEditingControl;
DataGridViewTextBoxCell cel = (DataGridViewTextBoxCell)dataGridView1.Rows[currentcell.Y].Cells[0];
cel.Value = sendingCB.EditingControlFormattedValue.ToString();
}

二。添加DatagridviewComboBox下拉组合框内容的二种方式
//方式一
((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[2]).Items.Add("A" );
((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[2]).Items.Add("B");
((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[2]).Items.Add("C" );
//方式二
List<string> ListData = new List<string> { "A", "B", "C" };
((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[2]).DataSource = ListData;
三。组合框内容的显示
//1要设置显示类型 2要设置的值为组合列表内的元素
this.Section.ValueType = typeof(string);
this.Section_data.Rows[index1].Cells[2].Value = "B";
四。数据库小技巧
1:DataGridViewComboBoxCell 有3个值:null\true\false
2:字典作为数据源的绑定方法
((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[4]).DataSource = new BindingSource(_typeDic, null); ((DataGridViewComboBoxCell)this.Section_data.Rows[index1].Cells[4]).ValueMember = "Key";//文本对应的值
3:ComboBox组件的数据绑定,三个属性是:“DisplayMember”、 “ValueMember”、“DataSource”。其中
"DataSource"是要显示的数据集
DisplayMember绑定的是需显示的字段 给用户看
ValueMember绑定的是对应的值 给程序员用
4:查询语句中字段名表名建议一律加[] 否则 字段中出现空格 特殊字符(比如“-”) 报错现象