Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1175
Creating an UltraDataSource with more than 2 hierarchy levels
posted

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;
}

Parents
  • 469350
    Suggested Answer
    Offline posted

    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;

Reply Children