我有创建弹出菜单的代码:
private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
{
GridView view = sender as GridView;
// Check whether a row is right-clicked.
if (e.MenuType == DevExpress.XtraGrid.Views.Grid.GridMenuType.Row)
{
int rowHandle = e.HitInfo.RowHandle;
// Delete existing menu items, if any.
e.Menu.Items.Clear();
// Add a submenu with a single menu item.
e.Menu.Items.Add(CreateRowSubMenu(view, rowHandle));
}
}
DXMenuItem CreateRowSubMenu(GridView view, int rowHandle)
{
DXSubMenuItem subMenu = new DXSubMenuItem("Rows");
DXMenuItem menuItemDeleteRow = new DXMenuItem("&Delete Row",
new EventHandler(OnDeleteRowClick));
menuItemDeleteRow.Tag = new RowInfo(view, rowHandle);
subMenu.Items.Add(menuItemDeleteRow);
return subMenu;
}
并删除GridView中的选定行:
void OnDeleteRowClick(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("Delete Row?", "Deleting", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
DXMenuItem item = sender as DXMenuItem;
RowInfo info = item.Tag as RowInfo;
info.View.DeleteRow(info.RowHandle);
dataAdapter.Update((DataTable)bindingSource1.DataSource);
}
}
我想对两个GridView使用OnDeleteRowClick
方法:master和detail。对于主GridView,我想调用dataAdapter.Update
和详细的GridView dataAdapterDetail.Update
方法。
是否可以确定GridView(主控或详细信息)究竟是什么引发了弹出事件?或者是否可以将引发弹出菜单的GridView作为参数传递给OnDeleteRowClick
方法。