Hi There,
I have a list of Accounts and each Account has various details and also a list of specific details. How can I display this data in xamDataGrid?
xamDataGrid->DataSource = List<Account>
Account
{
string field1
string field2,
string field3,
List<string> listOfFields
........
}
Never mind. I got my answer.
Binding a DataSet hierarchically to a XamDataGrid when AutoGenerateFields is set to false:(1) Bind the XamDataGrid DataSource to the parent table (or its DataView)(2) Define two FieldLayout sections in the FieldLayouts block for each of the tables(3) Add a Field with the same name as the data relation between the two tables to the parent table FieldLayout block.
Here is the part of code,
===============================
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="field1" Label="Field1" Width="100" /> <igDP:Field Name="field2" Label="Field2" Width="100" /> <igDP:Field Name="field3" Label="Field3" Width="100" /> <igDP:Field Name="ParentChild" Width="100" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout> <!-- Display details --> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="detail1" Label="detail1" Width="100"/> <igDP:Field Name="detail2" Label="detail2" Width="100"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
Thanks
I have a similar requirement to display data hierarchically, but not from Observable Collection, from Data Set. Here is the sample code,
public partial class MainWindow : Window{ public MainWindow() { InitializeComponent(); DataSet data = LoadData(); //DataContext = data; } private DataSet LoadData() { DataSet ds = new DataSet("Account"); DataTable root = new DataTable("root"); root.Columns.Add("accountId"); root.Columns.Add("field1"); root.Columns.Add("field2"); root.Columns.Add("field3"); DataTable child = new DataTable("child"); child.Columns.Add("id"); child.Columns.Add("detail1"); child.Columns.Add("detail2"); ds.Tables.Add(root); ds.Tables.Add(child); ds.Relations.Add(new DataRelation("ParentChile", root.Columns["accountId"], child.Columns["id"], false)); root.Rows.Add("a", "a1", "a2", "a3"); root.Rows.Add("b", "b1", "b2", "b3"); root.Rows.Add("c", "c1", "c2", "c3"); child.Rows.Add("a", "da1", "da2"); child.Rows.Add("a", "da12", "da22"); child.Rows.Add("a", "da13", "da23"); child.Rows.Add("b", "db1", "db2"); child.Rows.Add("b", "db12", "db22"); child.Rows.Add("b", "db13", "db23"); return ds; }}
--------------------------------
<Window x:Class="BindHierarchicalDataSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:igDP="http://infragistics.com/DataPresenter" xmlns:igEditors="http://infragistics.com/Editors" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:data="clr-namespace:BindHierarchicalDataSample" Title="MainWindow" Height="350" Width="525"> <Grid> <igDP:XamDataGrid Name="dataGrid" DataSource="{Binding}"> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="field1" Label="Field1" Width="100" /> <igDP:Field Name="field2" Label="Field2" Width="100" /> <igDP:Field Name="field3" Label="Field3" Width="100" /> <!--<igDP:Field Name="listOfDetails" Width="100" />--> </igDP:FieldLayout.Fields> </igDP:FieldLayout> <!-- Display details --> <!--<igDP:FieldLayout> <igDP:FieldLayout.Fields> <igDP:Field Name="detail1" Label="detail1" Width="100"/> <igDP:Field Name="detail2" Label="detail2" Width="100"/> </igDP:FieldLayout.Fields> </igDP:FieldLayout>--> </igDP:XamDataGrid.FieldLayouts> </igDP:XamDataGrid> </Grid></Window>
=======================================
Please advise.
Thanking you in advance for your help.
Hello Nasir,
I am very glad that my approach was helpful to you. Please let me know if you have any further questions.
Hello Gergana,
Thanks for solving this for me. I really appreciate your help.
Regards,
Nasir
I have been looking into your issue and have further modified the sample with the functionality you mentioned. Please find the attached sample and feel free to contact us if you have any further questions.