Skip to main content
Home Forums Silverlight Programming Silverlight Controls and Silverlight Toolkit datagrid collapsed setting displayindex
4 replies. Latest Post by snelldl on January 2, 2009.
(0)
snelldl
Member
148 points
141 Posts
01-01-2009 12:36 PM |
I've been working with the datagrid, setting the column order in various events after setting the ItemsSource. I keep getting the invalid index error whenever the datagrid is either collapsed or is inside of a control that is collapsed, even if I try to set the order during the LayoutUpdated event. That is, it seems to be that I can only set the column order in code behind of the datagrid is visible. Does this make sense?
MarkBetz
Participant
1142 points
211 Posts
01-01-2009 1:52 PM |
I'm not much of an expert on the DataGrid, but what I think is going on is that you have DataGrid.AutoGenerateColumns == true, and since the control is collapsed the DataGrid.Columns.Count is 0. You can try setting AutoGenerateColumns to false and building the columns yourself procedurally. If you do that then I believe they will remain persistent when the control isn't rendering.
01-01-2009 5:35 PM |
I'm not autogenerating columns.
lee_sl
Contributor
2992 points
585 Posts
01-02-2009 7:26 AM |
I would just add a check to see if the columns count is > 0
01-02-2009 9:18 AM |
Her's an interesting twist: I have a dg that is not collapsed inside of a scroll viewer that is collapsed, all declared in xaml. At run time, I set the dg's itemssource, then change the displayorder of the columns. I know they get changed because their order causes the sort order of another dg (that is visible) to be different from the default. I get no error during all this.
However, when I click a button that makes the scroll viewer visible, a 4004 error is thrown, indicating that one of the indexes in the dg inside the scroll viewer is not allowed.
I can get rid of this error by setting the dg display order back to the same order as it's itemssource, making the scroll viewer visible, then reording the columns during the dg's layoutupdated event. This is my current work around for the problem.
BTW, I am using the December release of the datagrid.