如何获得当鼠标悬停在Radgridview时的行索引
问题描述:
我想获得我的鼠标在任何行的索引,而不一定是从选定的行。如何获得当鼠标悬停在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可能返回GridView的元素,它们不一定是Cells,DataCells会更精确。不要忘记检查光标下面的内容。
由于MouseHover事件不提供有关坐标的信息,因此可能应该使用MouseMove事件,或者可以使用Cursor.Position属性。
从 http://www.telerik.com/forums/determining-the-mouse-down-position-in-cell 和 mouse 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
[旧telelink](http://www.telerik.com/forums/finding-the-grid-row-item-under-the-mouse-pointer),很可能已经改变,但有代码在那里可用于下载 –
答案必须更简单:( – vicangel