I have raw data coming in as a datatable. I need to massage it into an ultradatasource to provide a treeview like view in the ultragrid we are using. Are there any examples of doing this? Or is there a better route to take?
Hi Kevin,
There are basically two approaches you could take.
Approach one would be to create an UltraDataSource, create the Band and columns, then loop through your data source and copy the data into the UltraDataSource. This is pretty straightforward and I could help you with some sample code if you need it.
The second approach is to skip the last step where you copy the data and use OnDemand. This means you still create the UltraDataSource with the bands and columns, but then you simply handle the InitializeDataRow and CellDataRequested events to pull the data from your real data source. If you allow updating, then you would have to handle another event or two to write the data back to your data source.
I suppose, depending on what you actually need to do with the data, there might be a third option, like binding the grid directly to your DataTable and then creating a hierarchy using OutlookGroupBy to group the data.
Hi Mike,
Thanks for the quick reply! Unfortunately my customer wants data in a hierarchical format so binding the datatable is out. The good news is that this is a read only display as this will be a master view with a detail pane where they can fine tune things. The datatable will have about 12 columns and x number of rows. The first 5 columns basically have to be nodes the remainder of the columns provide additional infomation underneath the last node. The first approach you mentioned sounds like the direction I need to go in. Any sample code would be greatly appreciated. This is a C# project I am working in. Something else I wondered is that creating this treeview like view in the grid will I be to create selection check boxes to a select a node? Is this feasible?
Thanks :)
It's a little tough for me to give you sample code without knowing what you intend to do to the DataTable to make the flat data into a hierarchy.
But I assume you probably just need some guidance on how to set up your UltraDataSource with hierarchcal data, so here's a very simple example of how you might do that.
this.ultraDataSource1.Reset(); this.ultraDataSource1.Band.Columns.Add("Column 0", typeof(int)); this.ultraDataSource1.Band.Columns.Add("Column 1", typeof(string)); UltraDataBand childBand = this.ultraDataSource1.Band.ChildBands.Add("Child Band"); childBand.Columns.Add("Column 0", typeof(int)); childBand.Columns.Add("Column 1", typeof(string)); for (int i = 0; i < 10; i++) { UltraDataRow parentRow = this.ultraDataSource1.Rows.Add(new object[] { i, "Row " + i.ToString() }); for (int j = 0; j < 3; j++) { parentRow.GetChildRows(0).Add(new object[] { j, "Row " + j.ToString() }); } } this.ultraGrid1.DataSource = this.ultraDataSource1;
ahhh ok... adding the rows is what I was having the problem with. Thank you for the help!!