如何在 Radgridview 中鼠标悬停时获取行的索引

How to get index of row when MouseHover in 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

上面的代码做了我想要的,但是对于选定的行,当我的鼠标悬停在该行上时,我想获取行的索引。有人可以帮忙吗?

您应该可以按照以下说明获取单元格。从中获取行和列索引应该不难。

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

由于 GetElementAtPoint 可以 return GridView 的元素,这些元素不一定是 Cells,更准确地说是 DataCells。不要忘记检查光标下的内容。

由于 MouseHover 事件不提供有关坐标的信息,也许您应该改用 MouseMove 事件,或者您可以使用 Cursor.Position 属性.

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

我真正的问题是...我想在特定列中添加工具提示,工具提示显示另一列的值,这里是执行此操作的代码。

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