Skip to main content

Microsoft Silverlight

Unanswered Question datagrid collapsed setting displayindexRSS Feed

(0)

snelldl
snelldl

Member

Member

148 points

141 Posts

datagrid collapsed setting displayindex

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
MarkBetz

Participant

Participant

1142 points

211 Posts

Re: datagrid collapsed setting displayindex

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.

snelldl
snelldl

Member

Member

148 points

141 Posts

Re: datagrid collapsed setting displayindex

I'm not autogenerating columns.

lee_sl
lee_sl

Contributor

Contributor

2992 points

585 Posts

Re: Re: datagrid collapsed setting displayindex

I would just add a check to see if the columns count is > 0

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

snelldl
snelldl

Member

Member

148 points

141 Posts

Re: Re: datagrid collapsed setting displayindex

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.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities