Hello,
We are using collections as datasource to ultrawingrid. How to display data hierarchically in ultagrid for a collection based datasource. we could achive this by using dataset & datarelation. But need to achieve the same with non dataset based datasources.
Thanks,
Hi,
For example, you have the datasource like this: List of Customers and List of Orders related with each Customer.
You should create two bands in UltraDataSource according to this hierarchy.First band - should be parent. Second - child. You can do it in designer or dynamicly.
Then You can populate your Grid like this:
foreach (Customer customer in Customers) { UltraDataRow row = dataSource.Rows.Add(); row["Name"] = customer.Name; foreach (Order order in customer.Orders) { UltraDataRowsCollection childRows = row.GetChildRows("Band 1"); UltraDataRow childRow = childRows.Add(); childRow["OrderName"] = order.Name; childRow["Status"] = order.Status; childRow["OrderData"] = order.Data; }
}
grid.DataSource = dataSource;
// dataSource - is UltraDataSource
An UltraDataSource would be on good way to go. You can also bind the grid directly to a collection. To acheive a hierarchy, the objects in the collection just need to expose a public property (or properties) that return other collections.
hi Mike,
I added a collection and able to get the hierarchy representation of the data, thanks for that.
Could you please let me know how to change the column display name and width of the column in the heirarchy collection... when i did try to access band[1] thrwing exception as out of range exception.
Please do help on this..Awaiting for some light on this issue.
What's the exception?
If you can see Bands[1] at run-time, but are getting an IndexOutOfRange Exception when trying to access in code, the most likely reason is that you are just doing it too early - before the grid has created the band.
An easy way to avoid that is to use the InitializeLayout event of the grid to do any kind of layout and formatting you need:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; layout.Bands[1].Columns["My Column"].Header.Caption = "My Caption"; layout.Bands[1].Columns["My Column"].Width = 200; }
Hey Mike,
I am binding the collection to ultrawingrid with 3 level hierarchy and am looking to change the band names for these levels, as the first level band name is getting a wierd name as List`1 to some meaningful name.
Could you please help me on this.
Thanks In Advance
The band Key comes from the data source and cannot be changed in the grid.
You can change the Caption of the band header which is displayed to the user, but not the Key.