Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
My goal is to have the cursor turn into an "Ibeam" when the mouse is hovering over a cell that is read-only. However I'm having no luck. Is there a better way to accomplish this?


VB
Private Sub DataGridView1_MouseHover(sender As Object, e As EventArgs) Handles DataGridView1.MouseHover
      If DataGridView1.CurrentCell.ReadOnly = True Then
          DataGridView1.Cursor = Cursors.IBeam 
      Else
          DataGridView1.Cursor = Cursors.Default
      End If
  End Sub



  Private Sub DataGridView1_MouseLeave(sender As Object, e As EventArgs) Handles DataGridView1.MouseLeave
      DataGridView1.Cursor = Cursors.Default
  End Sub
Posted
Updated 3-Jun-13 9:15am
v4
Comments
Sergey Alexandrovich Kryukov 30-May-13 13:29pm    
It is a problem, or what? You did not ask any questions.
—SA
Kenneth Haugland 30-May-13 16:40pm    
I have som equestion here, is this WinForm or WPF, In that case it is a VSTO problem. If you use Excel macro programming it is called VBA, but your datagridview seems it is not or?

VB
Private Sub DataGridView1_CellMouseMove(sender As Object, e As EventArgs) Handles DataGridView1.CellMouseMove

    Dim columnIndex as Integer = e.ColumnIndex

    If DataGridView1.Columns(columnIndex).ReadOnly Then
        Cursor.Current = Cursors.IBeam
    Else
        Cursor.Current = Cursors.Default
    End If
End Sub
 
Share this answer
 
Have you tested on cell enter and leave versus hover?

Found this here ... Change mouse cursor on DataGridViewCell Hover[^]

HTH I don't have time to test. :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900