Hierarchical GDBG problem

Hi,
I would like to allow a user to display data from a datatable and in option to display the data in hierarchical format.
The scenario is :
1- I Init the gdbg with a datatable.
2- Dynamically, I display the data in hierachical format by adding relations ...
3- I remove all relations, and I display the data in a non hierachical format. All this works fine.
4- But when I try to re-display the data in hierachical format, it doesn't work. I have an empty grid.

The source code is :

-------------------------------------------------
// Display Hierarchical Data
public void GroupBy(String colname) {
this.internalGrid.BeginUpdate();
this.internalGrid.BeginInit();
this.internalGrid.ShowTreeLines = true;
this.internalGrid.Binder.ResetHierarchyLevels();
this.internalGrid.IndentHierarchies = true;

DataSet ds = GetDataSet();
ds.Tables.AddRange(new DataTable[] {_dataTableParent});

DataRelation parentToChild = new DataRelation ("ParentToChild",_dataTableParent.Columns[colname], _model.Data.Columns[colname], false);

ds.Relations.AddRange(new DataRelation[] {parentToChild});

this.internalGrid.Binder.SetDataBinding(ds, _dataTableParent.TableName);
this.internalGrid.DataSource = ds;
this.internalGrid.DataMember = _dt.TableName;
this.internalGrid.EndInit();

GridHierarchyLevel level0 = this.internalGrid.Binder.RootHierarchyLevel;
GridHierarchyLevel level1 = this.internalGrid.Binder.AddRelation("ParentToChild");

this.internalGrid.EndUpdate();
}

// Display in "Normal" Format
public void RemoveLink() {
DataSet ds = _model.Data.DataSet;
DataTable _dt = ds.Tables["ParentTable"];
this.internalGrid.BeginUpdate();
this.internalGrid.Binder.ResetHierarchyLevels();
_dt.ChildRelations.Clear();
ds.Tables.Remove("ParentTable");
this.internalGrid.BeginInit();
this.internalGrid.DataMember = null;
this.internalGrid.DataSource = null;

this.internalGrid.DataSource = _model.Data;
this.internalGrid.EndInit();
this.internalGrid.ShowTreeLines = false;
this.internalGrid.EndUpdate();
}
-------------------------------------------------

Thanks a lot for your help.
Sim







1 Reply

AD Administrator Syncfusion Team October 27, 2006 12:22 PM UTC

Hi Sim,

To show the relation in a grid( after changing the relation to underlying datasource), you need to call the AddRelation method. Below is a code snippet

GridHierarchyLevel childrenLevel =gridDataBoundGrid1.Binder.AddRelation("Parent_Child");
childrenLevel.ShowHeaders = false;

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/MasterRelationReset_e5e3bf67.zip

Let me know if this helps.
Best Regards,
Haneef

Loader.
Up arrow icon