Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse hover DataGridView

Status
Not open for further replies.

jpinto

Technical User
Dec 12, 2003
75
0
0
PT
Hello,

I want to change the cursor type when the mouse goes over a certain column in a dataview. I've the following code:

Code:
Private Sub DataGridView1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.MouseHover
        If DataGridView1.CurrentCell.ColumnIndex = 7 Then
            DataGridView1.Cursor = Cursors.Help
        Else
            DataGridView1.Cursor = Cursors.Default
        End If
    End Sub

The problem is that when entering the DataView, the cursors goes over the headers and I receive an error because there is no CurrentCell!
Can annyone help me please?

Thanks,

João Pinto
 
How about:

Private Sub DataGridView1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.MouseHover

[red]If DataGridView1.CurrentCell Is Nothing Then Return[/red]

If DataGridView1.CurrentCell.ColumnIndex = 7 Then
DataGridView1.Cursor = Cursors.Help
Else
DataGridView1.Cursor = Cursors.Default
End If
End Sub

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Ack multiple exit points!

Code:
Private Sub DataGridView1_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.MouseHover

    If not DataGridView1.CurrentCell Is Nothing Then 
        If DataGridView1.CurrentCell.ColumnIndex = 7 Then
            DataGridView1.Cursor = Cursors.Help
        Else
            DataGridView1.Cursor = Cursors.Default
        End If
    end if
End Sub

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Yeah, I'm sloppy sometimes. Sorry. :(

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day! Ye has a choice: talk like a pira
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top