Gridview cell cursor style

alfardan
alfardan used Ask the Experts™
on
Hi

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?
Comment
Watch Question

Do more with

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

Commented:
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;
        else{
            this.Cursor = Cursors.Default;
}
    }

Open in new window


based on http://goneale.com/2009/05/26/datagridview-tricks-1-set-hand-cursor-for-entire-cell/
Full stack Software Engineer
Commented:
here's in vb.net:

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

Open in new window

Author

Commented:
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