DataGridView 中动态加入ComboBox

来源:互联网 发布:淘宝售后差评回复 编辑:程序博客网 时间:2024/05/08 19:40
 
 public static void DataGridAddCobx(DataGridView DataGD, ComboBox Cobx)          {              try              {                  DataGD.Controls.Add(Cobx);                  Rectangle rect = DataGD.GetCellDisplayRectangle(DataGD.CurrentCell.ColumnIndex, DataGD.CurrentCell.RowIndex, false);                  Cobx.Left = rect.Left;                  Cobx.Top = rect.Top;                  Cobx.Width = rect.Width;                  Cobx.Height = rect.Height;                  Cobx.Visible = true;              }              catch (Exception ex)              {                  throw new Exception(ex.Message);              }         }


调用:

如第三列动态加入comboBox1

  if (this.dataGridView1.CurrentCell.ColumnIndex == 2)                {                   DataGridAddComBox(this.dataGridView1, comboBox1);                }                else                {                    this.comboBox1.Visible = false;                }


 

原创粉丝点击