Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
932
Clearing Fields and readding them back to FieldLayout does not work when there are child rows.
posted

 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;
        }
    }

Parents Reply Children
No Data