我只想问一下如何调用datagridview_cellclick,在这段代码中我有一个switch case,因为我的datagridview中有一个不同的按钮
这是我在datagridview_cellclick
中的代码 private void dgvFilter_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
switch (this.dgvFilter.Columns[e.ColumnIndex].Name)
{
case "ColumnButtonField":
DataGridViewCell GridColumnLoc = this.dgvFilter.CurrentCell;
GridColumnLoc.Value = "..";
this.cmbField.Visible = true;
//cmbField.Items.Remove(this.txtName.Text);
iRowIdx = e.RowIndex;
Rectangle RECT = this.dgvFilter.GetCellDisplayRectangle(4,
GridColumnLoc.RowIndex, true);
cmbField.Top = RECT.Top;
cmbField.Left = RECT.Left;
cmbField.Width = RECT.Width;
break;
case "ColumnButtonRemove":
DataGridViewRow GridRowLoc2 = this.dgvFilter.CurrentRow;
this.dgvFilter.Rows.Remove(GridRowLoc2);
//GVGLCode.DataBind();
DataGridViewCell GridColumnLoc2 = this.dgvFilter.CurrentCell;
GridColumnLoc2.Value = "..";
iRowIdx = e.RowIndex;
Rectangle RECTRem = this.dgvFilter.GetCellDisplayRectangle(5,
GridColumnLoc2.RowIndex, true);
cmbField.Top = RECTRem.Top;
cmbField.Left = RECTRem.Left;
cmbField.Width = RECTRem.Width;
//GVGLCode.DataBind();
break;
}
}
catch { }
我想要的是在case "ColumnButtonRemove":
有没有办法可以在组合框的selectedIndexChanged中调用它?还是按一下按钮?提前感谢您的帮助。
答案 0 :(得分:0)
您可以拨打DataGridView
的受保护功能OnCellClick
:
OnCellClick(new DataGridViewCellEventArgs(columnIndex, rowIndex));
由于它是受保护的功能,您必须扩展DataGridView
类才能访问它。
无论如何,更好的做法是创建一个包含columnButtonRemove
CellClick
代码的函数,以便您可以在CellClick
事件中{{1 event,...)。