前端之家收集整理的这篇文章主要介绍了
[VB.NET]datedridview,如何判断选中的不是标头?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
datedridview,如何判断选中的不是标头? datedridview,如何判断选中的不是标头? Private Sub DataGridView1_select(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged if 选中的是标头 then message
Box.show( xxx ) end if __________________________________________________________________________ private void dataGridView1_CellMouseClick(object sender,DataGridViewCellMouseEventArgs e) { System.Windows.Forms.DataGridView.HitTestInfo info = this.dataGridView1.HitTest(e.X,e.Y); System.Console.WriteLine(info.Type); if (info.Type == DataGridViewHitTestType.ColumnHeader) { Console.WriteLine( 点在了列头上了 ); } } __________________________________________________________________________ VB.NET
代码如下: Private Sub DataGridView1_MouseDown(ByVal sender As System.Object,ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseDown Dim info As DataGridView.HitTestInfo = Me.DataGridView1.HitTest(e.X,e.Y) If (info.Type = DataGrid.HitTestType.ColumnHeader) Then Console.WriteLine( 点在了列头上了 ) End If End Sub __________________________________________________________________________ 谢谢。SelectionChanged 事件上有没有
解决方案? __________________________________________________________________________ Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseClick Dim info As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X,e.Y) Message
Box.Show(info.Type.ToString) end sub 怎么Message
Box.show出来的都是ColumnHeader __________________________________________________________________________ 也是可以的,不过你要用Control.MousePosition来得到当前鼠标在DataGridView上的位置: Point point = this.DataGridView.PointToClient(Control.MousePosition); __________________________________________________________________________