We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

highlighting a row when mouse moves over the row

I''m using a GridDataBoundGrid, and I''m trying to get the background color of a row to change when the mouse is over that row. The row is not currently selected yet, just being hovered over. First I tried this... private void Grid_MouseMove(object sender, MouseEventArgs e) { bool validCell; int col, row; validCell = this.PointToRowCol(new Point(e.X, e.Y), out row, out col); if (validCell && row > 0) { this.Model.RowStyles[row].BackColor = Color.LightGoldenrodYellow; } } But that didn''t work, so I tried this.... private void Grid_MouseMove(object sender, MouseEventArgs e) { bool validCell; int col, row; validCell = this.PointToRowCol(new Point(e.X, e.Y), out row, out col); if (validCell && row > 0) { mouseOverRow = row; } } private void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { if (e.RowIndex == mouseOverRow) { e.Style.BackColor = Color.LightGoldenrodYellow; } else { e.Style.ResetBackColor(); } } that didn''t work either because PrepareViewStyleInfo only fires once. Help!

3 Replies

AD Administrator Syncfusion Team December 29, 2005 04:54 AM UTC

Hi Eric, Here is a sample which uses CellHitTest event and PrepareViewStyleInfo event to change the back color of the mouse hovering row. Regards, Calvin.

39142.zip


EW Eric Weber December 29, 2005 05:12 PM UTC

Thanks Calvin, that''s exactly what I was looking for. I see one side effect however, and was wondering you might have a work around. I''m sending you back your sample with some slight mods.... 1. In generate table... this.gridDataBoundGrid1.Model.ColStyles["Address"].WrapText = true; this.gridDataBoundGrid1.Model.ColStyles["Address"].AutoSize = true; 2. In Form load... this.gridDataBoundGrid1.Model.RowHeights.ResizeToFit(GridRangeInfo.Table()); After you run the sample... 1. resize the window so that you can see the entire grid 2. click in the cell at row 1, column 3 (the long address) 3. now move your mouse down to another row 4. Do you see how the cell you clicked on repaints itself continusously? Any ideas? Thanks!!!

39142_with_row_resize.zip


ST stanleyj Syncfusion Team December 30, 2005 01:30 PM UTC

Hi Eric, Calling Refresh in CellHitTest repaints itself continuously. This is an another try, see if this helps. In this, the current cell is moved with the mouse cursor so as to highlight based on the row that has current cell and while editing, the current cell is locked and released in next cell click. Here is the sample. Best regards, Stanley

Loader.
Live Chat Icon For mobile
Up arrow icon