DataGridView中实现combobox的selectindexchange事件
1 在想要实现的gridview中,先不要设置combobox列,比如有一列需要显示等级(高,中,低);那么你再grid中添加一列正常列,把数据帮上去;
2 再fromload的过程中,添加一个private combobox cmb_Temp= new ComboBox();
设置cmb_Temp.items.addrange((object){"高","中","低"});//添加数据源
cmb_Temp.visible = false;
this.grid.controls.add(cb);
3 添加cmb_Temp的selectindexchange事件,以及事件的委托;//你想要再选择的时候发生的事情都再indexchange事件里面写好;
4 添加grid的CurrentCellChanged,再这个事件中
if (this.PriceDataGridView.CurrentCell.OwningColumn.Name == "等级")
{
Rectangle rect = PriceDataGridView.GetCellDisplayRectangle(PriceDataGridView.CurrentCell.ColumnIndex, PriceDataGridView.CurrentCell.RowIndex, false);
if (PriceDataGridView.CurrentCell.Value != null)
{
cmb_Temp.Text = Convert.ToString(PriceDataGridView.CurrentCell.Value);
}
else
{
PriceDataGridView.CurrentCell.Value = cmb_Temp.Text;
}
cmb_Temp.Left = rect.Left;
cmb_Temp.Top = rect.Top;
cmb_Temp.Width = rect.Width;
cmb_Temp.Height = rect.Height-2;
cmb_Temp.Visible = true;
}
else
{
cmb_Temp.Visible = false;
}