Hi,
Relate with this post: http://forums.infragistics.com/forums/t/20265.aspx
I want to create an hierarchical datagrid but instead be automatic I want to create it manually.
For example, I have a ObervableCollection<Person> , but for each person I want to convert Person.Id to a DataTable with the current loans via WPF converter derived class and show that DataTable nested to the Person row.
Wich will be the correct way to do it?
I'm using:
<igDp:FieldLayout.Fields> <igDp:Field Name="Name" Row="0" Column="0"/> <igDp:Field Name="Surname" Row="0" Column="1"/> <igDp:Field Name="Title" Row="0" Column="2"/> <igDp:Field Name="Id" Converter="{StaticResource loanConverter}" Row="1" Column="0" ColumnSpan="3" IsExpandable="True" /> </igDp:FieldLayout.Fields> </igDp:FieldLayout>
Where loanConverter returns a DataTable, but the bottom row appears empty.
Cheers.
Hello,
Yes, I see -- I believe the two forum threads that are closest to what you need are here:
http://forums.infragistics.com/forums/p/2686/16176.aspx#16176
http://forums.infragistics.com/forums/p/11555/43656.aspx#43656
xamDataGrid does not automatically resolve metdata from objects, it just reads public properties from objects and creates fields from that. For hierarchy, it relies on collections (ObservableCollection<type>), but then again, the type needs to be known beforehand. ADO.NET DataTable is not supported automatically, so you will probably need to enumerate all columns from the DataTable and create the Fields yourself automatically (e.g. FieldsSettings[0] for root, FieldSettings[1] for child, etc).
In your case I believe following the suggestions in the top two forum will help.
Is there no way to avoid the WrapperClass step? We're looking to be able to control the grid's look much more dynamically *programatically*, and be able to override the default behaviour for some fields. IOW, for us it doesnt boil down to simple cases:-
1. DataSet with DataRelations
2. static Object tree with only top-level properties being considered.
For example in some cases, the data we are trying to render might have a list of objects, each of which contains a set of properties. One might be a block of XML that we can convert to an object. The other might be a DataTable.
Is this type of thing possible using XamDataGrid?For example if I have
class X
{
public object[ Properties;
}
and I want to bind to it, what do I do? Is my only route to convert it to a DataSet/Table and bind to that?
One specific thing I'm trying to do is to bind to a log which will contain
DateTime LogTime string Sourcestring messageDataTable sourceData
DateTime LogTime
string Source
string message
DataTable sourceData
Each DataTable could have a different schema, so if I have 100 log entries I cant really create a DataSet with 101 tables and 100 DataRelations.
When I bind to it, the DateTime and string fields work, but the DataTable doesnt.
Is there a way, maybe by setting up an UnboundField with a CellValuePresenterStyle to say "to render the cells for the sourceData column, please use this template and pass it the data you are trying to render" ?
Is there a sample that does something dynamic like this without using a DataSet?
You can define the field layouts manually and set the name of every layout with the name of the corresponding property of the WrapperClass and the grid will automatically map each property to the its field.
<igDp:FieldLayout.Fields> <igDp:Field Name="Name" > <igDp:Field Name="Surname" /> <igDp:Field Name="Title" /> <igDp:Field Name="Id"/> </igDp:FieldLayout.Fields> </igDp:FieldLayout>
public class Person { public string Name { get; set; } public string Surname{ get; set; } public string Title{ get; set; }
public string Id{ get; set; } }
Am I missing something else?
That works fine when you are going to use AutoGenerateFields, but if you want to define your own field layout... how do you do it?
I think that the most appropriate way to do this is to bind the XamDataGrid to an ObservableCollection<WrapperClass>, where the class WrapperClass contains one field with the Person and one with his/her loan and then bind it directly to the DataSource of the XamDataGrid.
Hope this helps.