Windows Develop Bookmark and Share   
 index > Windows Forms General > Unable to synchronize gridview scrollbars
 

Unable to synchronize gridview scrollbars

I have two grids. Grid A - 24 columns as header grid. Grid B- 48 columns as data. For Grid B I am hiding header row.
Now, it shows one column of Grid A for Two columns of grid B (common header for 2 columns of grid B).
I have horizontal scroll bar for Grid B. Trying to synchronize scrolling of grid A as below:

grdHeaderMonth.FirstDisplayedScrollingColumnIndex = (grdBookingMonth.FirstDisplayedScrollingColumnIndex / 2)+1 ;

grdHeaderMonth.HorizontalScrollingOffset = (grdHeaderMonth.HorizontalScrollingOffset) ;

But, if I scroll the grid by moving horizontal bar (not end buttons) it doesnt get synchronized. And lines of grid are not matching.

Can anybodysuggest alternative?


nilesh k
nilesh Kalyankar  Wednesday, September 23, 2009 8:39 AM

Hi nilesh,

When we handle the Scroll event, the FirstDisplayedScrollingColumnIndex and HorizontalScrollingOffset properties are not changed immediately. In other words, they still kept the old values. We can get the new scroll parameters via the Scroll event arguments. This is the code snippet:
private void grdBookingMonth_Scroll(object sender, ScrollEventArgs e)

{

if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)

{

grdHeaderMonth.HorizontalScrollingOffset = e.NewValue;

}

}

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 30, 2009 2:58 AM
Are you using the Scroll event to synchronize the two grids? If not, you should.

I tested the Scroll event of the GridView control and it seems to work OK in every case. The catch is that you only get scroll types of Small and LargeIncrements. You never get a scroll event with e.Type set to any other value. If you have an IF statement that differentiates between scroll types, then try removing it.
MCP
webJose  Wednesday, September 23, 2009 4:01 PM
Yes, I am using Grid B's scroll event.
I am not sure about the formula - (grdBookingMonth.FirstDisplayedScrollingColumnIndex / 2)+1
However, problem occurs for the first time when form is loaded.
I tried to write the same code on form load. but, Grid B gets scrolled to desired position and Grid A shows first column only.

Could you please suggest whether my approach is correct?

nilesh k
nilesh Kalyankar  Saturday, September 26, 2009 4:00 PM

Hi nilesh,

When we handle the Scroll event, the FirstDisplayedScrollingColumnIndex and HorizontalScrollingOffset properties are not changed immediately. In other words, they still kept the old values. We can get the new scroll parameters via the Scroll event arguments. This is the code snippet:
private void grdBookingMonth_Scroll(object sender, ScrollEventArgs e)

{

if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)

{

grdHeaderMonth.HorizontalScrollingOffset = e.NewValue;

}

}

Let me know if this does not help.
Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Wednesday, September 30, 2009 2:58 AM

You can use google to search for other answers

Custom Search

More Threads

• Easy way to format textbox without negative numbers
• Datagrids and arraylists
• Windows Form and Crystal Report in VS2005 listbox
• Trying to emulate a feature in Java layout manager for sizing controls in Visual Studio
• Highlighted Items in a ComboBox
• Reg:MSMQ 3.0 for xp
• PrintPreviewDialog Margins
• Locking Width of form from resizing
• Get Mouse pointer position
• Windows Application freezes