Ticket Q286639
Visible to All Users

How to hot-track GridView cells?

created 13 years ago

Hi Nick,

Thanks for the prompt reply. Your solution works very well, but it highlights the entire row. How can I edit it to make it paint only the cell?

Answers

created 13 years ago (modified 12 years ago)

Hi Serdar,
All you need is to introduce the HotTrackColumn property similar to the HotTrackRow one and take it into account in the gridView1_RowCellStyle method.

C#
private int hotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle; private int HotTrackRow { get { return hotTrackRow; } set { if(hotTrackRow != value) { int prevHotTrackRow = hotTrackRow; hotTrackRow = value; if(gridView1.ActiveEditor != null) gridView1.PostEditor(); gridView1.RefreshRowCell(prevHotTrackRow, HotTrackColumn); gridView1.RefreshRowCell(hotTrackRow, HotTrackColumn); if(hotTrackRow >= 0) gridControl1.Cursor = Cursors.Hand; else gridControl1.Cursor = Cursors.Default; } } } private GridColumn hotTrackColumn; private GridColumn HotTrackColumn { get { return hotTrackColumn; } set { if (hotTrackColumn != value) { GridColumn prevHotTrackColumn = hotTrackColumn; hotTrackColumn = value; if (gridView1.ActiveEditor != null) gridView1.PostEditor(); gridView1.RefreshRowCell(HotTrackRow, prevHotTrackColumn); gridView1.RefreshRowCell(HotTrackRow, HotTrackColumn); if (hotTrackColumn.VisibleIndex >= 0) gridControl1.Cursor = Cursors.Hand; else gridControl1.Cursor = Cursors.Default; } } } private void gridView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { GridView view = sender as GridView; GridHitInfo info = view.CalcHitInfo(new Point(e.X, e.Y)); if (info.InRowCell) { HotTrackRow = info.RowHandle; HotTrackColumn = info.Column; } else HotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle; } private void gridControl1_MouseLeave(object sender, System.EventArgs e) { HotTrackRow = DevExpress.XtraGrid.GridControl.InvalidRowHandle; } private void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { if(e.RowHandle == HotTrackRow && e.Column == hotTrackColumn) e.Appearance.BackColor = Color.PaleGoldenrod; }

Attached is a modified project.

    Comments (2)
    SB SB
    Serdar Benderli_1 13 years ago

      Uriah,
      Thanks for the help. Your solution is almost perfect, but I have one more question regarding performance. I want to allow hot-tracking only when there's a drag operation. So, I tried to do this by adding the following condition in MouseMove event:
      if (e.Button == MouseButtons.Left && info.InRowCell)
      And this 'mostly' works, however there are numerous occasions where the hot tracking won't update even though the mouse has moved. This performance is even more often in my solution where the application is much more complex and memory intensive. Is there any suggestion you can give me to improve the hot-tracking performance?

      DevExpress Support Team 13 years ago

        Hello Serdar,
        It appears that the GridView.RefreshRow method is insufficient when the drag and drop operation is executing. Please try to use the GridView.LayoutChanged method, instead.

        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.