DataGridView ScrollBars [solved]
-
I've been playing around with a DataGridView today. X| One of the things I noticed is that the ScrollBars behave differently when the thumb is dragged... The vertical ScrollBar scrolls the rows one whole row at a time. The horizontal ScrollBar scrolls the columns smoothly (which I suppose is usually the desired behaviour). Because all my columns are the same width (and narrow -- think of a Scrabble board implemented with a DGV) I would prefer to scroll a whole column at a time. Has anyone here achieved this? This isn't actually a big deal, just a "nice to have". (I expect someone at MS considered it a YAGNI.) Solution: In my earlier attempts, I had been trying to force the scrollbar to jump by the column width. Altering the HorizontalScrollingOffset directly to a value that is a multiple of the column width (X below) achieves the desired effect.
private void
dgResults_Scroll
(
object sender
,
System.Windows.Forms.ScrollEventArgs e
)
{
if ( e.ScrollOrientation == System.Windows.Forms.ScrollOrientation.HorizontalScroll )
{
this.dgResults.HorizontalScrollingOffset = e.NewValue / X * X ;
}return ;
}
modified on Thursday, September 24, 2009 5:21 PM