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
........
}
Hello Nasir,
Thank you for your post. I have been researching your issue and created a small sample for you.
Please find the attached sample and do not hesitate to contact us if you have any further issues.
Gergana,
Thanks for your reply and sample app. It really helped.
I don't want auto generated fields in the grid. Because I don't want to hide some of fileds (columns) in grid and I want to format fields differently. How can I do that. I made following changes in the code but it isn't working as I would like to,
==========================================================================
<igDP:XamDataGrid Name="myDataGrid" DataSource="{Binding}" Theme="IGTheme">
<igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings AutoGenerateFields="False" /> </igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts> <igDP:FieldLayout> <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="ListOfDetailses.detail1" Label="Field" Width="100"/>--> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
-------------------------------------------------------
ObservableCollection<Accounts> data = new ObservableCollection<Accounts>();
data.Add(new Accounts { field1 = "text1", field2 = "text1", field3 = "text1",
ListOfDetailses =new List<AccountDetails>
new AccountDetails{detail1="a1",detail2="a2"},
new AccountDetails{detail1="b1", detail2="b2"},
new AccountDetails{detail1="c1", detail2="c2"},
DataContext = data;
============================================================================
Please let me know.
Thanks
Nasir
I have further investigated your issue and have modified the previous sample so that it implements the behavior you mentioned. Please find the attached sample and do not hesitate to contact us if you have any further questions.
Hello Gergana,
Thank you for reply. I ran the sample app. But it still doesn't display account details. It displays field1, field2 and field3. When I click on > (first column or a row), it should display account details in a new row bellow it. Please let me know.
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.
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>
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.
I am very glad that my approach was helpful to you. Please let me know if you have any further questions.
Thanks for solving this for me. I really appreciate your help.
Regards,