控制DataGirdView中單元格

this.dataGridView1.EditingControlShowing += new DataGridViewEditingControlShowingEventHandler(dataGridView1_EditingControlShowing);

void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
  {
   if (e.Control is DataGridViewComboBoxEditingControl)
   {
    if (!isRegedit)
    {
     ((DataGridViewComboBoxEditingControl)e.Control).DropDown += new EventHandler(uclMPODetailListView_DropDown);
     ((DataGridViewComboBoxEditingControl)e.Control).SelectedIndexChanged += new EventHandler(uclMPODetailListView_SelectedIndexChanged);
     ((DataGridViewComboBoxEditingControl)e.Control).KeyDown += new KeyEventHandler(uclMPODetailListView_KeyDown);
     isRegedit = true;
    }

   }
   else
   {
    isRegedit = false;
   }

   if (e.Control is ImageButtonTextBoxEditingControl)
   {
    if (dataGridView1.CurrentCell.ColumnIndex == 0)
    {
     //if (!((ImageButtonTextBoxEditingControl)e.Control).HasRegedited)
     //{
     ((ImageButtonTextBoxEditingControl)e.Control).ReSetClickEvent();
     ((ImageButtonTextBoxEditingControl)e.Control).imageButtonClicked += new EventHandler(uclMPODetailListViewMO_imageButtonClicked);
      //((ImageButtonTextBoxEditingControl)e.Control).HasRegedited = true;
     //}
    }

    if (dataGridView1.CurrentCell.ColumnIndex == 18)
    {
                    ((ImageButtonTextBoxEditingControl)e.Control).KeyPress += new KeyPressEventHandler(imageCtrl_KeyPress);
     ((ImageButtonTextBoxEditingControl)e.Control).ReSetClickEvent();
     ((ImageButtonTextBoxEditingControl)e.Control).imageButtonClicked += new EventHandler(uclMPODetailListViewPO_imageButtonClicked);
    }
   }
  }

        void imageCtrl_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = true;
        }

原文地址:https://www.cnblogs.com/springxie/p/1509542.html