如何通过右键单击获取超级网格视图的列索引
当我右键单击超级网格视图或可能是网格视图时。 我想为不同的列显示不同的上下文菜单条。 但是当我右键单击时,我得到了我选择的列的索引,而不是我右键单击的列的索引。 我该怎么得到它.. 代码如下:
Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button() = Windows.Forms.MouseButtons.Right Then
MessageBox.Show(DataGridView1.SelectedCells(0).ColumnIndex.ToString())
End If
End Sub
When i right click on ultra grid view or may be grid view .
I want to display different contextmenu strip for different columns.
But when i right click i get index of column which i selected not which i right clicked.
How should i get it..
Code is as follows:
Private Sub DataGridView1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown
If e.Button() = Windows.Forms.MouseButtons.Right Then
MessageBox.Show(DataGridView1.SelectedCells(0).ColumnIndex.ToString())
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(2)
墨洒年华2024-12-25 07:16:13
您需要使用 hitTest 来获取您正在寻找的列索引,例如:
If e.Button = Windows.Forms.MouseButtons.Right Then
Dim hit As DataGridView.HitTestInfo = _
DataGridView1.HitTest(e.X, e.Y)
MsgBox(hit.ColumnIndex.ToString)
End If
我个人对 UltraGrid 并不熟悉,但它应该具有相同的功能,就像大多数网格控件一样。如果没有,您可以使用以下内容:
http://devcenter.infragistics.com/Support /KnowledgeBaseArticle.aspx?ArticleID=1750
并对其进行调整以提供该列。
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
将 UltraColumn 置于光标下的最佳方法是利用 UltraGrid 类的 MouseUp 事件。
这是 C# 示例,但我相信您会明白我的想法:
The best way to get UltraColumn under the cursor is to utilize MouseUp event of the UltraGrid class.
Here is sample in C# but i'm sure you will catch my idea: