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;
                  }

转载于:https://www.cnblogs.com/zany-hui/articles/1043257.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值