Hello,
My requirement is lazy binding of the column layout. On click of any cell of a row or on click of the expansion indicator of row, I want to load the data for columnlayout in code behind and keep that row in expanded state. With the events - void dataGrid_CellClicked(object sender, Infragistics.Silverlight.CellClickedEventArgs e) { IsCellClicked = true; ActiveRow = (Row)e.Cell.Row; lstCurrentData = (List<ChildNode>)dataGrid.ItemsSource;
string strSelectedID = ((ChildNode)e.Cell.Row.Data).ID; List<ChildNode> lstChildren = new List<ChildNode>(); lstChildren = GetTheDataByParentID(strSelectedID); /* To get the children assign to respective node */ SearchRecursive(lstCurrentData, strSelectedID, lstChildren);
dataGrid.ItemsSource = null; dataGrid.ItemsSource = lstCurrentData; dataGrid.UpdateLayout(); }and void dataGrid_RowExpansionChanged(object sender, Infragistics.Silverlight.RowExpansionChangedEventArgs e) { List<ChildNode> vm = dataGrid.DataContext as List<ChildNode>; lstCurrentData = (List<ChildNode>)dataGrid.ItemsSource; string strSelectedID = ((ChildNode)e.Row.Data).ID; List<ChildNode> lstChildren = new List<ChildNode>(); lstChildren = GetTheDataByParentID(strSelectedID); SearchRecursive(lstCurrentData, strSelectedID, lstChildren); dataGrid.ItemsSource = null; dataGrid.ItemsSource = lstCurrentData; dataGrid.UpdateLayout(); }I get the data in ColumnLayout, but I need the respective row in expanded state. Now as the code in RowExpanded event is reassigning the ItemSource, its not allowing the row to expand on expander arrow click. But as I want to load the data for column layout at the time of expand, I've to do it in that event itself. Is there any other way for this? Please, help.Thanks,Pragati.
Hello Pragati,
Thank you for your post. I have been looking into it and it seems like that this is the best way of achieving the thing you want. If I think of a batter way, I will let you know.
Hello Stefan,I'm using the dll Infragistics.Silverlight.XamWebGrid.v9.2, VS 10, SL4. My data is of multiple depth heirarchy.As I need lazy binding, I tried it orher way. I get the another XamWebGrid in ColumnLayout through TemplateColumn - DataTemplate. To get the cell click event of this grid added in xaml's resources - <UserControl.Resources> <DataTemplate x:Name="MyDataTemplate"> <Grid> <igGrid:XamWebGrid CellClicked="dataGrid_CellClicked" ItemsSource="{Binding Children}"/> </Grid> </DataTemplate></UserControl.Resources>
In code behind -
void dataGrid_RowExpansionChanging(object sender, Infragistics.Silverlight.CancellableRowExpansionChangedEventArgs e) { if (IsRowAlreadyExpanded == false && e.Row.IsExpanded == false) { ActiveRow = (Row)e.Row; dataGrid_CellClicked(sender, new Infragistics.Silverlight.CellClickedEventArgs()); } } void dataGrid_CellClicked(object sender, Infragistics.Silverlight.CellClickedEventArgs e) { if (ActiveRow == null) ActiveRow = (Row)e.Cell.Row; CustomerNode objnode = new CustomerNode(); lstCurrentData = (List<ChildNode>)dataGrid.ItemsSource;
strSelectedID = ((ChildNode)ActiveRow.Data).ID; List<ChildNode> lstChildren = new List<ChildNode>(); /* To get the children of respective node */ lstChildren = objnode.GetTheDataByParentID(strSelectedID, lstParentChildData); /* To search and assign the children to respective nodes for grid ItemSource */ SearchRecursive(lstCurrentData, strSelectedID, lstChildren); if (lstChildren.Count > 0) { TemplateColumn objTempleteColoumn; objTempleteColoumn = new TemplateColumn() { Key = "Children", ItemTemplate = (DataTemplate)this.Resources["MyDataTemplate"] }; try { e.Cell.Column.ColumnLayout.Columns.Add(objTempleteColoumn); ////e.Cell.Row.ColumnLayout.Columns.Add(objTempleteColoumn); } catch (Exception) { throw; } }
IsRowAlreadyExpanded = false; ActiveRow = null; } With this, I get the children data bounded to the grid in template, but I'm not getting the heirarchical display. I get like -
Actually, the grid should be assigned as a child of first row, as I've clicked the cell in first row & data is updated respectively. Please, let me know the better way, how I can assign this Grid of children in columnlayout, if I'm having the same parent in multiple(non-clicked) rows. Additionaly, the basic requirement is I need the specific row & its upper heirarchy in expanded state. Thanks,Pragati.