如何在Radgridview中的MouseHover时获取行的索引

时间:2017-06-07 13:44:03

标签: vb.net winforms 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

上面的代码执行我想要的但是对于所选行,当我的鼠标位于此行上时,我想获取行的索引。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

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

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

由于GetElementAtPoint可以返回不一定是Cell的GridView元素,因此DataCells更精确。别忘了检查光标下面的内容。

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

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

答案 1 :(得分: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