so far I have been able to get 2 levels of a hierarchy, but when I try to add the 3rd I don't see how to get the row to add the next hierarchy level, the code will allow a user to run a query for the base hierarchy, then they can select a record and run another query, which will put a hierarchy under that row containing the selected record, I've got that working, but when I try to add another hierarchy under that second hierarchy, I don't see how I get the row in order to add the next hierarchy, below is the code I'm using to create this hierarchy tree, I have to use an ultragrid as well because I allow the user to do a lot of sorting and filtering on the data, Thank you for your time, Jamie
This code loads my first hierarchy
for (int i = 0; i < dt.Columns.Count; i++){ ultraDataSource1.Band.Columns.Add(dt.Columns[i].ColumnName, dt.Columns[i].DataType);}
for (int i = 0; i < dt.Rows.Count; i++){ ultraDataSource1.Rows.Add(dt.Rows[i].ItemArray);}ultraGrid1.DataSource = ultraDataSource1;
Here is the code I use to load all hierarchies below the parent hierarchy
if (ultraGrid1.Selected.Rows.Count >= 1){ for (int i = 0; i < ultraGrid1.Selected.Rows.Count; i++) { UltraDataBand ucb = ultraDataSource1.Band.ChildBands.Add("ChildBand" + intChildBandCount);
for (int j = 0; j < dt.Columns.Count; j++) ucb.Columns.Add(dt.Columns[j].ColumnName, dt.Columns[j].DataType);
UltraDataRow udr = null; if(ultraGrid1.Selected.Rows[i].ParentRow==null) udr = ultraDataSource1.Rows[ultraGrid1.Selected.Rows[i].Index]; //Get selected row to add hierarchy else { UltraDataBand udbTemp = ultraDataSource1.Band.ChildBands[ultraGrid1.Selected.Rows[i].Band.Key];
//I don't see how to get the selected row here in order to add the hierarchy }
UltraDataRowsCollection childBand0ChildRows = udr.GetChildRows("ChildBand" + intChildBandCount);
for (int j = 0; j < dt.Rows.Count; j++) childBand0ChildRows.Add(dt.Rows[j].ItemArray); } ultraGrid1.DataSource = ultraDataSource1;}
Hi,
It appears that you are adding a new child band to the data source and then adding a row through the grid. This is certainly feasible, but it seems a bit odd. The grid is basically a UI component for the user to use. It's more efficient, and will keep your code more consistent, for you to add a row directly to the data source, rather than through the grid.
So.. if you want a build a 3-level hierarchy in the UltraDataSource, you would do something like this:
// Add columns to band 0. this.ultraDataSource1.Band.Columns.Add("Column 0 in Band 0", typeof(int)); this.ultraDataSource1.Band.Columns.Add("Column 1 in Band 0", typeof(string)); // Add a child band. UltraDataBand childBand = this.ultraDataSource1.Band.ChildBands.Add("Band 1"); childBand.Columns.Add("Column 0 in Band 1", typeof(int)); childBand.Columns.Add("Column 1 in Band 1", typeof(string)); // Add a grandchild band. UltraDataBand grandChildBand = childBand.ChildBands.Add("Band 2"); grandChildBand.Columns.Add("Column 0 in Band 2", typeof(int)); grandChildBand.Columns.Add("Column 1 in Band 2", typeof(string)); // Add a row to band 0. UltraDataRow row = this.ultraDataSource1.Rows.Add(new object[] { 0, "Row 0 in Band 0" }); // Add a child row to the parent row. UltraDataRow childRow = row.GetChildRows(childBand).Add(new object[] {0, "Child Row 0 in band 1" }); // Add a Grandchild Row UltraDataRow grandChildRow = childRow.GetChildRows(grandChildBand).Add(new object[] { 0, "Grandchild Row 0 in band 2" }); this.ultraGrid1.DataSource = this.ultraDataSource1;
Hi Mike,
I followed this method for adding Parent,Child, Grandchild data to an Ultradatasource. It all works fine. I then set the datasource of an ultrawingrid to the ultradatasource. So far so good...
The problem that I have is that in the initialisation of the UltraWinGrid I only have 2 bands Parent and Child with the 3rd band Grandchild being a hidden column in band 2. How can i modify the layout and which fields are to be shown in the grandchild band?
e.layout.band[0].columns["columnname"] is what i use for the band 0 and similarly for band 1 replacing 0 with 1 in the band[]. But this doesn't work in Band[2] as it doesn't exist
Regards,
Alex
Hi Alex,
I'm afraid you lost me.
judgedredge said:The problem that I have is that in the initialisation of the UltraWinGrid I only have 2 bands Parent and Child with the 3rd band Grandchild being a hidden column in band 2. How can i modify the layout and which fields are to be shown in the grandchild band?
I don't understand what this means. Are you still referring to the sample I posted or some other application? What do you mean when you say the Grandchild band is "a hidden column in band 2"? I child band is represented by a column in the parent band, but it's a special kind of column and you should not be setting the Hidden property on a chartered column. If you want a hide a band, you should use the Hidden property on the band.
But if you want the grandchild band to show up, why are you hiding it?
I must be misunderstanding what you wrote here.