views:

759

answers:

2

I have two silverlight (2 or 3) datagrids (from the July 2009 Silverlight toolkit) positioned one on top of the other. The top datagrid holds values, the bottom datagrid holds summary values (e.g. total). I want their respective columns to be aligned at all times, even as the user changes the column header widths, column order, and as the user scrolls horizontally. How can this be done?

I'm using two datagrids because I want the total values in the lower datagrid to be visible at all times, as the user scrolls the contents of the top datagrid vertically.

I've tried to access the horizontal scrollbar of the datagrid using GetVisualDescendants(), but this returns no elements. How can this be done? I'm guessing it can be done because Silverlight Spy shows the visual hierarchy.

A: 

I'd suggest you put both of them inside a grid with the width set to the width of the grids. Then put that grid inside of a scroll viewer. Then you will have a single scrollbar at the bottom that will scroll both grids.

If you really want two scrollbars then use the method above but put them both in scroll viewers and attach to the OnScroll event. Then you can use the values from that event to programatically scroll the other scroll viewer.

Bryant
Could this method be extended to handle the column width resizing, reordering, and frozen columns (which I forgot to mention)>
Phillip Ngan
Probably not column resizing since this is very tricky to do. I've tried storing the resized column sizes for users in the past and there isn't a clean way to do it that I know of. You might be able to tie into the datagrid resized event (which is fired on column resize) and resize the lower grid. Once that is working I'd explore changing the actual column sizes.
Bryant
A: 

If you are still lokking for this...contact me at [email protected] I have written a DataGridSynchronizer class which synchronizes Scrolling and Column resizing and you can extend it for other things also. See if this can solve your problem

lawazia
@lawazia, thanks, but yes we have solved the synchronization problem using OnCreateAutomationPeer to retrieve the scrollprovider. Thx.
Phillip Ngan