[英]Devexpress datagrid and form context menu
When i right click on grid row it shows context menu strip assigned to it for few second and then replace it with form's context menu. 当我右键单击网格行时,它会显示分配给它的上下文菜单条几秒钟,然后将其替换为表单的上下文菜单。 How can i make sure that grid's context menu strip remain visible if click is on grid.
如果单击网格,如何确保网格的上下文菜单栏保持可见。
Code: 码:
private void Form1_Load(object sender, EventArgs e)
{
Matches();
DataTable dt = new DataTable();
dt.Columns.Add("Test", typeof(string));
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
ContextMenuStrip ctsForm = new ContextMenuStrip();
ctsForm.Items.Add("Form");
ctsForm.Opening+=ctsForm_Opening;
ctsGrid.Items.Add("Grid");
gridControl1.DataSource = dt;
gridView1.PopupMenuShowing+=gridView1_PopupMenuShowing;
this.ContextMenuStrip = ctsForm;
}
private void ctsForm_Opening(object sender, CancelEventArgs e)
{
}
private void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
{
GridView view = (GridView)sender;
GridHitInfo hitInfo = view.CalcHitInfo(e.Point);
if (hitInfo.InRow)
{
view.FocusedRowHandle = hitInfo.RowHandle;
ctsGrid.Show(view.GridControl, e.Point);
}
}
Here is the possible solution: 这是可能的解决方案:
void Form1_Load(object sender, EventArgs e) {
DataTable dt = new DataTable();
dt.Columns.Add("Test", typeof(string));
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
dt.Rows.Add("A");
gridControl1.DataSource = dt;
ContextMenuStrip ctsForm = new ContextMenuStrip();
ctsForm.Items.Add("Form");
ctsForm.Opening += ctsForm_Opening;
this.ContextMenuStrip = ctsForm;
ContextMenuStrip ctsGrid = new ContextMenuStrip();
ctsGrid.Items.Add("Grid Row!");
ctsGrid.Opening += ctsGrid_Opening;
gridControl1.ContextMenuStrip = ctsGrid;
// gridView1.PopupMenuShowing removed at all
}
void ctsGrid_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
e.Cancel = !IsPointInGridRow(gridView1, gridControl1.PointToClient(Control.MousePosition));
}
void ctsForm_Opening(object sender, System.ComponentModel.CancelEventArgs e) {
// some code
}
static bool IsPointInGridRow(GridView view, Point pt) {
return view.CalcHitInfo(pt).InRow;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.