2017-06-07 43 views
0

我想获得我的鼠标在任何行的索引,而不一定是从选定的行。如何获得当鼠标悬停在Radgridview时的行索引

Private Sub RadGridView1_MouseHover(sender As Object, e As EventArgs) Handles RadGridView1.MouseHover 
      Try 
       toolidx = RadGridView1.CurrentCell.RowIndex 
       strphone = dsOrders.Tables(0).Rows(toolidx)("DeliveryPhone") 

      Catch ex As Exception 
       RadMessageBox.Show(ex.Message, projectName, MessageBoxButtons.OK, RadMessageIcon.Error) 
       errlog.WriteLog(ex.Message.ToString, Me.Name, System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()) 
      End Try 
     End Sub 

上面的代码做了我想要的,但对于选定的行,我希望在鼠标移动到该行时获取行的索引。谁能帮忙?

+0

[旧telelink](http://www.telerik.com/forums/finding-the-grid-row-item-under-the-mouse-pointer),很可能已经改变,但有代码在那里可用于下载 –

+0

答案必须更简单:( – vicangel

回答

0

您应该可以通过以下说明获取单元格。从它得到行列索引不应该很困难。

Dim cell As GridCellElement = TryCast(RadGridView1.ElementTree.GetElementAtPoint(e.Location), GridCellElement) 

由于GetElementAtPoint可能返回GridView的元素,它们不一定是Cells,DataCells会更精确。不要忘记检查光标下面的内容。

由于MouseHover事件不提供有关坐标的信息,因此可能应该使用MouseMove事件,或者可以使用Cursor.Position属性。

http://www.telerik.com/forums/determining-the-mouse-down-position-in-cellmouse coordinates in MouseHover event?

+0

非常感谢您的答案,但e.location不幸的是不接受在mouseHover事件我不想点击单元格我想只是将它悬停 – vicangel

+0

更新了我对你的位置问题的回答。 –

+0

非常感谢你的回答,也许我需要他们再次!我已经解决了我的问题。 – vicangel

0

我真正的问题是......我想添加在特定的列和工具提示工具提示在这里展示的另一列的值信用是代码来做到这一点。

Private Sub RadGridView1_ToolTipTextNeeded(sender As Object, e As ToolTipTextNeededEventArgs) Handles RadGridView1.ToolTipTextNeeded 
     Try 
      Dim cell As GridDataCellElement = TryCast(sender, GridDataCellElement) 

      If cell IsNot Nothing AndAlso cell.ColumnInfo.Name = "DeliveryName" Then  
       e.ToolTipText = cell.RowInfo.Cells.Item("DeliveryPhone").Value 

      End If 
     Catch ex As Exception 
      RadMessageBox.Show(ex.Message, projectName, MessageBoxButtons.OK, RadMessageIcon.Error) 
      errlog.WriteLog(ex.Message.ToString, Me.Name, System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()) 
     End Try 
    End Sub