Search code examples
vb.netwinformsradgridview

How to get index of row when MouseHover in Radgridview


i want to get index of any row that my mouse is above and not necessarily from the selected row.

 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

the code above does what i want but for the selected row i want to get the index of row when my mouse is over this row. Can anyone help?


Solution

  • You should be able to get the cell with the following instruction. Shouldn't be difficult to get the row and column index from it.

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

    As GetElementAtPoint could return element of GridView which are not necessarily Cells, DataCells to be more precise. Don't forget to check what is really under the cursor.

    As the MouseHover event do not give information about coordinates, maybe you should use the MouseMove event instead or you could use the Cursor.Position Property.

    Credit from http://www.telerik.com/forums/determining-the-mouse-down-position-in-cell and mouse coordinates in MouseHover event?