Gridview cell cursor style

alfardan used Ask the Experts™

I have a windows application that has a gridview, and this gridview has some rows added through a for loop.

There are some rows that I want the cursor to be (hand) and some others to be (default)

how do I assign (when the mouse hovers over a certain cell/row) "gridview.cursor = Cursors.Hand" on a cell/row level instead of the whole gridview?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Meir RivkinFull stack Software Engineer

first add a function IsHandCursorStyle which accept the row index and returns whether to change the cursor to hand (rather than default).

 then add CellMouseMove handler for the gridview to accomplish cursor change:

private bool IsHandCursorStyle(int rowIndex){
//add the logic here


    private void myDataGridView_CellMouseMove(object sender, DataGridViewCellMouseEventArgs e)

        if (IsHandCursorStyle(e.RowIndex) && e.ColumnIndex >= 0) {
}            this.Cursor = Cursors.Hand;
            this.Cursor = Cursors.Default;

Open in new window

based on
Full stack Software Engineer
here's in

Private Sub myDataGridView_CellMouseMove(sender As Object, e As DataGridViewCellMouseEventArgs)
	If IsHandCursorStyle(e.RowIndex) AndAlso e.ColumnIndex >= 0 Then
		Me.Cursor = Cursors.Hand
		Me.Cursor = Cursors.[Default]
	End If
End Sub

Open in new window


Works great, thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial