在C#中使用contextmenustirp时锁定datagridview滚动条 [英] Lock datagridview scroll bar while using contextmenustirp in C#
问题描述
所以我有一个ContextMenuStrip在DataGridView上工作,当我右键单击DataGridView中的一行时,它将显示ContextMenuStrip。问题是,如果我垂直向上和向下滚动,它应该在启用ContextMenuStrip时滚动。我想要做的是右键单击后滚动条基本上被锁定,只能在菜单出去后再次使用。
我有什么试过:
这是我目前的代码:
So I have a ContextMenuStrip working on a DataGridViewand when I right click on a row from the DataGridView it will show the ContextMenuStrip. The problems is, if I vertically scroll up and down it should't scroll while the ContextMenuStrip is enabled. What I am trying to do is after right click the scroll bar is basically locked and can only be used again after the Menu go out.
What I have tried:
This is the code I have at the moment:
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
ContextMenuStrip menu = new ContextMenuStrip();
if (e.Button == MouseButtons.Right)
{
var hti = dataGridView1.HitTest(e.X, e.Y);
int position = dataGridView1.HitTest(e.X, e.Y).RowIndex;
dataGridView1.ClearSelection();
dataGridView1.Rows[hti.RowIndex].Selected = true;
if (position >= 0)
{
menu.Items.Add("Open Explorer").Name = "Open Explorer";
menu.Items.Add("Pc Info").Name = "Pc Info";
}
menu.Show(dataGridView1, new Point(e.X, e.Y));
menu.ItemClicked += new ToolStripItemClickedEventHandler(menu_ItemClicked);
dataGridView1.ContextMenuStrip = menu;
}
}
我试图使用
I've tried to use
dataGridView1.ScrollBars = ScrollBars.None;
,但它不起作用。你知道我怎么能这样做吗?
, but it doesn't work. Do you have any idea how can I do this?
推荐答案
也许这样可行:
Maybe this will work:
dataGridView1.Enabled = false;
这篇关于在C#中使用contextmenustirp时锁定datagridview滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!