Hello,
We allow users to add, remove, reorder xamdatagrid fields using a custom editor. One user is done editing we remove old fields from the layouts and add the new fields and reset the datasource. This does not work properly as child rows are not displayed after that. Can you please help? We are creating both parent and child layouts from code behind.
we are using v11.1 but I was able to repro this with 10.3 as well. I have created a demo app showing this but unfortunately I can not attach here as it is not allowed from my workplace. However below is the code I have (please note that I am using the same Category/Books datasource that is used in many examples available in the IG forums)
<StackPanel> <igDP:XamDataGrid DataSource="{Binding}" Name="xamDataGrid1" VerticalAlignment="Top" BindToSampleData="False"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> </igDP:XamDataGrid> <Button Content="Go" Click="Button_Click" /> </StackPanel>
public partial class Window2 : Window { FieldLayout layoutChild; FieldLayout layout; ObservableCollection<Category> data; public Window2() { InitializeComponent(); data = new LibraryBusinessLogic().Categories; this.DataContext = data;
layoutChild = new FieldLayout(); layoutChild.Key = "Child"; AddChildFields(layoutChild); xamDataGrid1.FieldLayouts.Add(layoutChild);
layout = new FieldLayout(); layout.Key = "Parent"; AddPArentFields(layout); layout.Settings.ExpansionIndicatorDisplayMode = ExpansionIndicatorDisplayMode.CheckOnDisplay; xamDataGrid1.FieldLayouts.Add(layout); }
private static void AddPArentFields(FieldLayout layout) { var colm = new Field("Name", "Name"); layout.Fields.Add(colm); colm = new Field("Books", "Books") { IsExpandable = true }; layout.Fields.Add(colm); }
private static void AddChildFields(FieldLayout layoutChild) { var col = new Field("Isbn", "Isbn"); layoutChild.Fields.Add(col); col = new Field("Title", "Title"); layoutChild.Fields.Add(col); col = new Field("Author", "Author"); layoutChild.Fields.Add(col); }
// Do below ar runtime after use is done editing, for the sake of demo I have just added same fields back. private void Button_Click(object sender, RoutedEventArgs e) { xamDataGrid1.DataContext = null; layout.Fields.Clear(); AddPArentFields(layout);
layoutChild.Fields.Clear(); AddChildFields(layoutChild);
xamDataGrid1.DataContext = data; } }
Hello Naveen,
Thank you for the your post. I have created a sample application using the code snippet that you have provided me with and after researching the behavior that you have described, it seems that it is caused by the fact that each time when the expandable field is created, the XamDataGrid is creating a FieldLayout for that field and it is added to the FieldLayouts collection. You can avoid this behavior by using the AssignFieldLayoutToItem event of the XamDataGrid. This event allows you to specify, which FieldLayout will be used for each record that is added to the XamDataGrid. You can check the e.Item’s type and if it is from the type of the child layout, you can set the e.FieldLayout to the FieldLayout that you have created. I am attaching the sample application that I have created, which shows how you can implement this approach.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi Krasimir,
Thanks for you help, I am able to solve this issue by re-creating the layout from scratch rather just recreading fields.
Cheers,
Naveen
I am very glad that you have managed to solve the issue that you are having. Please let me know if you need any further assistance on the matter.