我有一个网格视图(dotnetbar中的超级网格),该视图具有上下文菜单条以删除一行。单击单元格后,gridview进入编辑模式。一旦上下文菜单选项完成了删除操作,我就需要使网格脱离编辑模式。
这是gridview进入编辑模式的方式:
private void superGrid1_CellClick(object sender, GridCellClickEventArgs e)
{
superGrid1.PrimaryGrid.KeyboardEditMode = KeyboardEditMode.EditOnKeystroke;
superGrid1.PrimaryGrid.MouseEditMode = MouseEditMode.SingleClick;
}
这是删除行的代码:
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var i = superGrid1.GetSelectedElements();
if (i.Count > 0)
{
if (MessageBox.Show("Do you want to delete this row?", "confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
superGrid1.PrimaryGrid.Rows.Remove(i[0]);
superGrid1.PrimaryGrid.PurgeDeletedRows();
superGrid1.PrimaryGrid.DataSource = mBatchData;
gridDataChanged = true;
}
}
else
{
//do nothing.
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//this is where the grid needs to get out of the edit mode
}
}