KB Article A2904
Visible to All Users

How to change the mouse cursor to a hand when the mouse moves over a cell

The hand cursor is shown automatically if RepositoryItemHyperLinkEdit or RepositoryItemHypertextLabel is assigned to a grid column.

To change the current cursor for an arbitrary cell, handle the GridView's MouseMove and MouseLeave events. Within the MouseMove event handler you need to determine whether the mouse pointer is over your cell or not and whether your additional conditions are satisfied. You can use Hit Information to check what visual element is located under Cursor. Then set the GridControl's Cursor property to the System.Windows.Forms.Cursors.Hand value if all conditions are satisfied and restore the cursor back to the default value otherwise.

C#
private void GridView1_MouseLeave(object sender, EventArgs e) { GridView view = sender as GridView; view.GridControl.Cursor = System.Windows.Forms.Cursors.Default; } private void GridView1_MouseMove(object sender, MouseEventArgs e) { GridView view = sender as GridView; GridHitInfo hi = view.CalcHitInfo(new Point(e.X, e.Y)); if (hi.InRowCell & YourOtherConditionsAreSatisfied(hi)) view.GridControl.Cursor = System.Windows.Forms.Cursors.Hand; else view.GridControl.Cursor = System.Windows.Forms.Cursors.Default; } bool YourOtherConditionsAreSatisfied(GridHitInfo hi) { bool result = true; // your conditions here return result; }

In the attachment, you will find a sample project which demonstrates this approach.

Also, you may want to check our quick-reference guide - it contains cheat sheets, best practices, and troubleshooting sections:
DevExpress WinForms Cheat Sheets

Show previous comments (1)
DevExpress Support Team 7 years ago

    Hi,

    Now, the hand cursor is shown automatically if RepositoryItemHyperLinkEdit or RepositoryItemHypertextLabel is assigned to a grid column. Since this article is quite old, I have updated it accordingly.

      What if the column has "readonly = true" and "allowedit = false"
      Then the cursor does not change to hand even when it has a repository item HyperTextLabel.
      How to do that ?
      (Winforms Gridview 18.1.14)

      DevExpress Support Team 4 years ago

        Hello,
        You can handle the GridView's MouseMove and MouseLeave events. Within the MouseMove event handler you need to determine whether the mouse pointer is over your cell or not and whether your additional conditions are satisfied. You can use Hit Information to check what visual element is located under Cursor. Then set the GridControl's Cursor property to the System.Windows.Forms.Cursors.Hand value if all conditions are satisfied and restore the cursor back to the default value otherwise.

        C#
        private void GridView1_MouseLeave(object sender, EventArgs e) { GridView view = sender as GridView; view.GridControl.Cursor = System.Windows.Forms.Cursors.Default; } private void GridView1_MouseMove(object sender, MouseEventArgs e) { GridView view = sender as GridView; GridHitInfo hi = view.CalcHitInfo(new Point(e.X, e.Y)); if (hi.InRowCell & YourOtherConditionsAreSatisfied(hi)) view.GridControl.Cursor = System.Windows.Forms.Cursors.Hand; else view.GridControl.Cursor = System.Windows.Forms.Cursors.Default; } bool YourOtherConditionsAreSatisfied(GridHitInfo hi) { bool result = true; // your conditions here return result; }

        In the attachment, you will find a sample project which demonstrates this approach.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.