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

frozen/static current row when scrolling

Hi, Is there an efficient way (i.e. speedy and no flickering) to make the current row (CurrentCell.RowIndex) static/frozen at a specific position in the visible part of the grid? So when scrolling down it's not the current row moving down, but the rows of the grid moving up. This to make the rows directly beneath the current row visible while scrolling. A lot of my customers complain they can not see what's present directly below the current row when scrolling, so they have to keep scroll down to make the rows visible, then a bit back up to start editing cells. It would be very nice if the grid could/can support this.

5 Replies

Administrator March 31, 2003 10:18 AM UTC

Here is a try at this. It derives the GridControl and overrides OnKeyDown to scroll things there if there is an up/down arrow key is pressed. There is a little flicker on the row header, but the whole row does not seem to flicker. public class MyGridControl : GridControl { protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { int inc = 0; if(e.KeyCode == Keys.Down && this.TopRowIndex > 1) { inc = -1; } else if(e.KeyCode == Keys.Up && this.ViewLayout.LastVisibleRow < this.RowCount) { inc = 1; } if(inc != 0) { this.BeginUpdate(); int cr = this.CurrentCell.RowIndex - this.TopRowIndex; int col = this.CurrentCell.ColIndex; this.CurrentCell.Deactivate(false); this.Selections.Clear(); this.TopRowIndex += inc; this.Selections.Add(GridRangeInfo.Row(this.TopRowIndex + cr)); this.EndUpdate(); //do one or the other of these lines this.CurrentCell.Activate(this.TopRowIndex + cr, 0); //this.CurrentCell.Activate(this.TopRowIndex + cr, col); } return; } base.OnKeyDown(e); } }

            

PV Patrick van der Plas April 1, 2003 04:38 AM UTC

Changed it into: if(e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { int inc = 0; if(e.KeyCode == Keys.Up && this.TopRowIndex > 1) { inc = -1; } else if(e.KeyCode == Keys.Down && this.ViewLayout.LastVisibleRow < this.RowCount) { inc = 1; } if(inc != 0) { this.BeginUpdate(); int cr = this.CurrentCell.RowIndex - this.TopRowIndex; int col = this.CurrentCell.ColIndex; this.CurrentCell.Deactivate(false); this.TopRowIndex += inc; this.EndUpdate(); //do one or the other of these lines //this.CurrentCell.Activate(this.TopRowIndex + cr, 0); this.CurrentCell.Activate(this.TopRowIndex + cr, col); } return; } But this causes a complete repaint of all individual (visible) cells (in my derived grid class), just like a pagedown, making it not very practical. I assume the normal way of (fast) scrolling involves blitting a part of the visible area up or down and only repainting a minimum of individual cells. Allthough the 'static current row' way of scrolling is more complicated, it should be possible to optimize by blitting. Can I make the grid work like that?

Administrator April 1, 2003 11:01 AM UTC

Patrick, you can actually leave out the Begin/EndUpdate calls. That way the display immediately after the Deactivate call so that before the grid is scrolled there are no "dirty" window areas. That way when scrolling only the new visible scroll area needs to be painted. Example: protected override void OnKeyDown(System.Windows.Forms.KeyEventArgs e) { if(e.KeyCode == Keys.Down || e.KeyCode == Keys.Up) { int inc = 0; if(e.KeyCode == Keys.Down && this.TopRowIndex > 1) { inc = -1; } else if(e.KeyCode == Keys.Up && this.ViewLayout.LastVisibleRow < this.RowCount) { inc = 1; } if(inc != 0) { int cr = this.CurrentCell.RowIndex - this.TopRowIndex; int col = this.CurrentCell.ColIndex; this.CurrentCell.Deactivate(false); this.TopRowIndex += inc; //if necessary you could also call here EndUpdate(true) to force updating new visible cells before setting current cell. this.CurrentCell.MoveTo(this.TopRowIndex + cr, col); } return; } base.OnKeyDown(e); } Stefan

Administrator April 1, 2003 11:09 AM UTC

You can try using GridControl.ScrollWindow to scroll things yourself.

PV Patrick van der Plas April 1, 2003 12:41 PM UTC

Now running without the BeginEndUpdate. Performance is very good. Just some minor flickering. If users start complaining about that I'll try 'ScrollWindow'ing to reduce it (or ignore them, which is more likely;-). Thx for the input!
Loader.
Live Chat Icon For mobile
Up arrow icon