Hello, I set Autogenerate = true because the columns will be dynamic. But, I need to add a unbound column ir-respective of the number of columns. Also, few mandatory columns will be present in all datasource which i need to format. So, I have defined fieldlayout, which doesnt seems to be working.
Please take a look at the attached sample, select Test1 and Test2 and you will notice the difference. Please advise on the solution for this.
Attaching the sample.
2nd try.. I keep getting an error with attachment.
Either the site is offline or an unhandled error occurred. We apologize and have logged the error. Please try your request again or if you know who your site administrator is let them know too.
Ok, below is the code.
public partial class MainWindow : Window { private DataTable t1 = new DataTable(); private DataTable t2 = new DataTable(); public MainWindow() { InitializeComponent(); t1.Columns.Add("RecordClass", System.Type.GetType("System.String")); t1.Columns.Add("KeyValue", System.Type.GetType("System.String")); t1.Columns.Add("DataValue", System.Type.GetType("System.String")); t1.Columns.Add("Dynamic1", System.Type.GetType("System.String")); t1.Columns.Add("Dynamic2", System.Type.GetType("System.String")); DataRow r = t1.NewRow(); r["RecordClass"] = "Class"; r["KeyValue"] = "Value1"; r["DataValue"] = "Data1"; r["Dynamic1"] = "Dynamic1"; r["Dynamic2"] = "Dynamic2"; t1.Rows.Add(r); t2.Columns.Add("RecordClass", System.Type.GetType("System.String")); t2.Columns.Add("KeyValue", System.Type.GetType("System.String")); t2.Columns.Add("DataValue", System.Type.GetType("System.String")); t2.Columns.Add("Dynamic1", System.Type.GetType("System.String")); t2.Columns.Add("Dynamic2", System.Type.GetType("System.String")); t2.Columns.Add("Dynamic3", System.Type.GetType("System.String")); DataRow r1 = t2.NewRow(); r1["RecordClass"] = "Class"; r1["KeyValue"] = "Value1"; r1["DataValue"] = "Data1"; r1["Dynamic1"] = "Dynamic1"; r1["Dynamic2"] = "Dynamic2"; r1["Dynamic3"] = "Dynamic3"; t2.Rows.Add(r1); } private void test1_Click(object sender, RoutedEventArgs e) { xamDataGrid1.DataSource = t1.AsDataView(); } private void test2_Click(object sender, RoutedEventArgs e) { xamDataGrid1.DataSource = t2.AsDataView(); } }
Xaml:
<Window x:Class="FieldLayoutSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:igDP="http://infragistics.com/DataPresenter"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <StackPanel Orientation="Vertical"> <Button x:Name="test1" Content="Test 1" Click="test1_Click" /> <Button x:Name="test2" Content="Test 2" Click="test2_Click" /> </StackPanel> <igDP:XamDataGrid Grid.Column="1" HorizontalAlignment="Left" Name="xamDataGrid1" VerticalAlignment="Top"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="True" HighlightAlternateRecords="True" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <!--<igDP:UnboundField Name="Remove" Width="Auto"> <igDP:UnboundField.Settings> <igDP:FieldSettings CellWidth="40" LabelWidth="40" CellValuePresenterStyle="{StaticResource cvpRemoveButton}" LabelPresenterStyle="{StaticResource lpTrashCan}" /> </igDP:UnboundField.Settings> </igDP:UnboundField>--> <igDP:Field Name="RecordClass" Visibility="Collapsed" /> <igDP:Field Name="KeyValue" Label="Key" Width="Auto" /> <igDP:Field Name="DataValue" Label="Value" Width="Auto" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid> </Window>
Hello,
Thank you for your post. I have been looking into it and the code you have provided and I created a sample project for you using it with the functionality you want. Basically I created the FieldLayout in the Click events of the Buttons before I changed the DataSource, so that the Fields can auto generate every time. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.