简体   繁体   English

使用 DatagridView 滚动保持上下文位置更改

[英]Keep context location change with DatagridView scroll

I have a datagrid View and code is我有一个数据网格视图,代码是

 DataGridView m_ClientProcessDataGridView = new DataGridView();

And I have a context menu and it is我有一个上下文菜单,它是

 ContextMenuStrip contextMenuStripForCells;

on right click on datagrid and showing context menu as右键单击数据网格并将上下文菜单显示为

contextMenuStripForCells.Show(m_ClientProcessDataGridView.PointToScreen(e.Location));

The issue is when I scroll datagridview context menu will not move with row position, do we have any idea to keep it move with scroll?问题是当我滚动 datagridview 上下文菜单时,它不会随行位置移动,我们有什么想法让它随滚动移动吗?

Or can I disable datagridview scroll when context is open ?或者我可以在上下文打开时禁用 datagridview 滚动吗?

Scroll by wheel happens in OnMouseWheel .滚轮滚动发生在OnMouseWheel You can override the method and check if the ContextMenuStrip is open, prevent scroll:您可以覆盖该方法并检查ContextMenuStrip是否打开,防止滚动:

public class MyDataGridView : DataGridView
{
    protected override void OnMouseWheel(MouseEventArgs e)
    {
        if (this.ContextMenuStrip != null && this.ContextMenuStrip.Visible)
            return;
        base.OnMouseWheel(e);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM