I am trying to save off a XamDataGrid's header re-arrangement in 8.2. I like how the user can now stack columns and the grid responds accordingly with drag and drop (Too sweet!!!). I can also see they can be arranged from xaml by setting Row and Column. This doesn't appear to work from code behind:LabelPresenter dlp = (LabelPresenter)_xamDataGrid.labelPresenterSource;
Field field = dlp.Field.Owner.Fields[1];
field.Row = 1;
I would expect my column to drop to the 2nd row.
I can see in the debugger that when I drag and drop a column header down a row, the Field.FieldGridPosition.Row private variable changes correctly, but the Field.Row variable does not change. Setting Field.Row does not change Field.FieldGridPosition.Row either.
-tia
Kurt
Can you please give an example how do I create custom FieldLayout in xaml and load it programaticaly?
Vlad Zagorski"] Hi Kurt, In runtime when you rearrange the columns actually you don't change the layout. In order to change the Fields Rows and Cols arrangements from Code Behind you have to replace the default FieldLayout with a new one. You can do it like this: 1. Set the XamDataGrid.DataSource to null; 2.Remove the default FieldLayout 3.Add a new custom FieldLayout (with the desired Rows and Cols) to the FieldLayouts 4.Set the AutoArrangeCells property of the XamDataGrid to "Never" 5.Rebind the XamDataGrid.DataSource private void btnChangeLayout_Click(object sender, RoutedEventArgs e){ FieldLayout layout1 = new FieldLayout(); Field f1 = new Field(); f1.Name = "FirstName"; f1.Row = 0; f1.Column = 0; Field f2 = new Field(); f2.Name = "LastName"; f2.Row = 1; f2.Column = 0; layout1.Fields.Add(f1); layout1.Fields.Add(f2); xamDataGrid1.DataSource = null; xamDataGrid1.FieldLayouts.Remove(xamDataGrid1.FieldLayot[0]); xamDataGrid1.FieldLayouts.Add(layout1); xamDataGrid1.FieldLayoutSettings.AutoArrangeCells = AutoArrangeCells.Never; xamDataGrid1.DataSource = customers; xamDataGrid1.UpdateLayout();} Also you can create a custom FieldLayout in xaml as Resource and then do the same steps to change the FieldLayout: FieldLayout layout = this.FindResource("customLayout") as FieldLayout; Best regards Vlad
Hi Kurt,
In runtime when you rearrange the columns actually you don't change the layout.
In order to change the Fields Rows and Cols arrangements from Code Behind you have to replace the default FieldLayout with a new one. You can do it like this:
1. Set the XamDataGrid.DataSource to null;
2.Remove the default FieldLayout
3.Add a new custom FieldLayout (with the desired Rows and Cols) to the FieldLayouts
4.Set the AutoArrangeCells property of the XamDataGrid to "Never"
5.Rebind the XamDataGrid.DataSource
private void btnChangeLayout_Click(object sender, RoutedEventArgs e){ FieldLayout layout1 = new FieldLayout(); Field f1 = new Field(); f1.Name = "FirstName"; f1.Row = 0; f1.Column = 0; Field f2 = new Field(); f2.Name = "LastName"; f2.Row = 1; f2.Column = 0; layout1.Fields.Add(f1); layout1.Fields.Add(f2);
xamDataGrid1.DataSource = null; xamDataGrid1.FieldLayouts.Remove(xamDataGrid1.FieldLayot[0]); xamDataGrid1.FieldLayouts.Add(layout1); xamDataGrid1.FieldLayoutSettings.AutoArrangeCells = AutoArrangeCells.Never; xamDataGrid1.DataSource = customers; xamDataGrid1.UpdateLayout();}
Also you can create a custom FieldLayout in xaml as Resource and then do the same steps to change the FieldLayout:
FieldLayout layout = this.FindResource("customLayout") as FieldLayout;
Best regards
Vlad
Hi Vlad, Thank you for the quick reply. I got it working by just modifying the fields in place. Re-creating them with all the same info used to build them with templates the first time would be a lot of info to save off. Here is all I had to do to stack them 2 rows deep.FieldLayout newLayout = dataGrid.FieldLayouts[0];for (int i=0; i<dataGrid.FieldLayouts[0].Fields.Count; i++){ dataGrid.FieldLayouts[0].Fields[i].Row = i %2; dataGrid.FieldLayouts[0].Fields[i].Column = i / 2;}
dataGrid.DataSource = null;dataGrid.FieldLayouts.Remove(dataGrid.FieldLayouts[0]);dataGrid.FieldLayouts.Add(newLayout);dataGrid.FieldLayoutSettings.AutoArrangeCells = AutoArrangeCells.Never;
dataGrid.DataSource = bindingSource;dataGrid.UpdateLayout();
Thanks again!