I hope someone can help me.
I'm working on displaying hierarchical data in a xamDataGrid. The data that I'm using is retrieved as a flat list. I've created a class in the same way that the LibraryBusinessLogic is layed out in the xamFeatureBrowser. The only difference is that rather than having specific properties for the classes for different levels,they hold a custom "item" object, and also the collection of any child "item". The item object then contains the various properties such as ID, Description etc...
The datagrid displays the data, but there is only one column named "Item" which then contains a long string of all the properties in the item object. I've tried field layouts like this:
<igDP:FieldLayout Key="TopLevel" > <igDP:FieldLayout.Fields> <igDP:Field Name="ItemID" /> <igDP:Field Name="ItemDescription" /> <igDP:Field Name="LastScanned" /> <igDP:Field Name="LocationDescription" /> </igDP:FieldLayout.Fields> </igDP:FieldLayout>
But it seems whatever I do, it only displays one column.
Is there any way to get it putting the properties into their own columns, or do I need to add public properties to each class to access the "item" properties that I want from it?
I can provide more information if it's not clear what I'm doing but I didn't want to confuse the initial post too much!
Many thanks!
Rob
Hi Rob,
A great way to display hierarchical data in the XamDataGrid is by ObservableCollection. I have recently created and posted a sample of that. Here is the link and hope this helps you. If you still have any trouble feel free to give me some more information on your problem.
http://forums.infragistics.com/forums/t/20031.aspx
I've decided to go with the public properties for now as it works and isn't a great hassle.
Another quick question. In terms of displaying the data, I'd like to have the top level display a header but not the lower levels. The only way I've found to do this so far is to alter my hierarchical class structure so I have a class dedicated to top level items called "DataGridScannedItems" and then a class for any child level items "DataGridItems"
Both classes are identical in structure, properties etc... but in order to have two seperate FieldLayouts (one with LabelLocation set to Default and the other for all child levels with LabelLocation set to Hidden), as far as I can make out I have to have two distinct classes so that the first FieldLayout can have it's key set to "DataGridScannedItems", and the second FieldLayout can have it's key set to "DataGridItems", thereby differentiating the two classes.
Is it possible to do this without needing the two classes that could otherwise be one class?
Here's the structure I started with for the hierarchical data: class DataGridDataSource { private ObservableCollection<DataGridItem> _dataGridItems; public ObservableCollection<DataGridItem> ScannedItems { get { return _dataGridItems; } } public void AddScannedItem(DataGridItem item) { if (_dataGridItems == null) { _dataGridItems = new ObservableCollection<DataGridItem>(); } _dataGridItems.Add(item); } } class DataGridItem { CoreServiceLibrary.ItemDataContract _item; ObservableCollection<DataGridItem> _childItems; public DataGridItem(CoreServiceLibrary.ItemDataContract item) { _item = item; } #region Public Properties public CoreServiceLibrary.ItemDataContract Item { get { return _item; } } public ObservableCollection<DataGridItem> ChildItems { get { return _childItems; } } #endregion public void AddChildItem(DataGridItem childItem) { if(_childItems == null) { _childItems = new ObservableCollection<DataGridItem>(); } _childItems.Add(childItem); } }That just displays one column with a string of all the properties for the (CoreServiceLibrary.ItemDataContract) Item.Adding the properties I want to display explicitly like this: class DataGridDataSource { private ObservableCollection<DataGridItem> _dataGridItems; public ObservableCollection<DataGridItem> ScannedItems { get { return _dataGridItems; } } public void AddScannedItem(DataGridItem item) { if (_dataGridItems == null) { _dataGridItems = new ObservableCollection<DataGridItem>(); } _dataGridItems.Add(item); } } class DataGridItem { CoreServiceLibrary.ItemDataContract _item; ObservableCollection<DataGridItem> _childItems; public DataGridItem(CoreServiceLibrary.ItemDataContract item) { _item = item; } #region Public Properties public string ID { get { return _item.ItemID; } } public string Description { get { return _item.ItemDescription; } } public DateTime? LastScanned { get { return _item.LastScanned; } } public string Location { get { return _item.LocationDisplayDescription; } } public ObservableCollection<DataGridItem> ChildItems { get { return _childItems; } } #endregion public void AddChildItem(DataGridItem childItem) { if(_childItems == null) { _childItems = new ObservableCollection<DataGridItem>(); } _childItems.Add(childItem); } }Has the desired effect. But I was hoping there was a way to not have to expose specific properties. Before using this hierarchical structure, my datasource was just ObservableCollection<CoreServiceLibrary.ItemDataContract> and this showed each property automatically as a seperate column.
Cheers,
Hi Alex,
I'm using ObservableCollection , the problem I'm having is that when I just had one observable collection that contained my custom "item" objects, the grid automatically showed the properties of the item class as individual columns.
Now I've changed the structure so that I have an ObservableCollection of "level" objects. Each "level" contains an "item" object and also has an ObservableCollection of "level" objects itself. This allows me to create a hierarchy with as many levels as I need.
The issue is that where I have a public property on the "level" class to access the "item" object within it, the datagrid then automatically takes this as being the only column to display and so shows all of the properties if the "item" object as one long string in that column, rather than showing each property of the "item" as a seperate column which it did originally.
By adding public properties to the "level" to access the properties of the "item" object that I want to display in columns, I achieve the desired result, but I was wondering if there's any way to get it to display them without having to add them as properties?