We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Dynamic # of levels in GDBG

I am planning to use GDBG in relational view. I have used it so many times and works like charm. This time I have to use it with little variation. Is it possible to have dynamic number of levels for each row? Something like Row1 has ‘child’, ‘grandchild’,’grandgrandchild’ Row2 has ‘child’, ‘grandchild’, ’grandgrandchild’, ’greatgrandgrandchild’ Row3 has ‘child’, ‘grandchild’ Row4 has ‘child’, ‘grandchild’, ’grandgrandchild’ Row5 has ‘child’, ‘grandchild’ Is it possible? If yes how can I do that? Please do reply! Regards, Atit

23 Replies

AD Administrator Syncfusion Team June 3, 2005 10:26 PM UTC

I found the following artical. http://www.syncfusion.com/Products/features.aspx?t=226 This is something that might work for me. Is there any working sample for this feature? regards, Atit

AD Administrator Syncfusion Team June 4, 2005 01:10 AM UTC

I really have to work this out. I understand it is bad time (weekend) but if someone can help me that would be great. At least just give me some direction. I need to make sure that this can be done. regrads, atit

AD Administrator Syncfusion Team June 4, 2005 02:49 AM UTC

The grid in the article is a GridGroupingControl. The only way I know that you would be able to do this with a GridDataBoundGrid is to know the maximum depth of the related tables, and set up that number of hierarchy levels to begin with. If a node does not have that many psopulated children, it will not show them.

AD Administrator Syncfusion Team June 4, 2005 04:01 PM UTC

Thanks clay, I am very well aware of GDBG. My problem is little different. In case of GDBG I guess I should know the depth of related tables. Most Imps: My problem is that I don’t know the depth of related tables. it is almost like recursion of table relations. Is it possible to use table relation in a recursive manner? It is almost like that each row has its own dataset. Is it possible to use multiple dataset and assign them to be used in hierarchical view? What exactly nested means in case of above article? I thought GridGroupingControl might the one, but if you could explain Regards, Atit

AD Administrator Syncfusion Team June 4, 2005 06:20 PM UTC

Here is a sample. It starts out by setting up one parent-child relation. When you expand a parent node, it dynamically adds child-grandchild relation, and when you expand a child node, it adds a grandchild to greatgrandchild relation. The sample has things set up to only hande this set of levels, but you could use ArrayLists of objects and write code that could handle an undetermined number of levels. http://www.syncfusion.com/Support/user/uploads/GGC_DynamicHier_f49aede6.zip

AD Administrator Syncfusion Team June 5, 2005 12:41 AM UTC

First of all you guys are great. This is really 24/7 support. You do really support your product. This is really great and would probably work for my case. Since I am more familiar with GDBG and had other things done for my existing version of GDBG. If I use GridGroupingControl then I will end up writing every thing again like printing, exporting etc.. again. My export to excel is very complicated. Most of all if I re-write then I would be asking to many question because I will be using GGC first time. Is it possible to use same idea in GDBG? That would be great if I could do that. Do you think that it could be done in GDBG? If yes, how can I do that? Please do help me! I am looking forward for your help. Atit

AD Administrator Syncfusion Team June 5, 2005 01:49 AM UTC

It takes more work. Here is a minimal sample. http://www.syncfusion.com/Support/user/uploads/GGC_DynamicHier_6630c946.zip

AD Administrator Syncfusion Team June 5, 2005 07:20 PM UTC

Thanks clay, That is great. I am trying to convert the sample for n# of levels. I am trying to understand the sample. #1 I couldn’t understand the purpose of SaveOpenRows & SetOpenRows methods. What exactly we are doing there? #2 In your sample you are using ‘RowExpanded’ event to expand the sample. In my case I have to check for something first on the clicked row then try to populate level from database. since every row might not have its child or lower level so I have to be selective. Should I still use ‘RowExpanded’ event? Why in your sampel you didn’t use the ‘RowExpanding’ event? What are the criteria of using both the events? I mean in which case should I use ‘RowExpanded’ or ‘RowExpanded’? Regrads, Atit

AD Administrator Syncfusion Team June 5, 2005 08:44 PM UTC

#3 I have one more question about pre-populating the grid. If I use grid.ExpandAll() in the form load event in your sample, is it going to populate the grid as if we populated by clicking each row on the grid? I am asking this because let say user open the grid and it is only showing paren-child. What if user wants to print/export to excel it before clicking on any row and populate each level? Since when user print the grid then it should print all the levels. Atit,

AD Administrator Syncfusion Team June 5, 2005 10:52 PM UTC

1) Comment out the calls to these methods and see what happens in the sample. You will see that resetting the datasource collapses the grid. So, you have ot save teh collapse state before resetting the datasource and then reset it afterwards. 2)I tried to used RowExpanding an dit did not work as easily as RowExpanded, so I changed it. The sample always populates a child portion of the new relation. So, when you click a row in teh parent table (if it is the first time child row is seen), then the gridchild table is populated. Even though the rows in the GridChild will not be seen until your user clicks a child row to expand it. The difference between RowExpanding and RowExpanded is tehat the first is a canceable event that is raised prior to teh row being expanded. The second is a notification event that is raised after the row is expanded. 3)What happened when you tried it? It seems to work for me.

AD Administrator Syncfusion Team June 6, 2005 04:04 PM UTC

Thanks clay, 3)What happened when you tried it? It seems to work for me. Yes. it is working for me too. Regrads, Atit

AD Administrator Syncfusion Team June 7, 2005 07:54 PM UTC

Hi clay, Please help me. I am having problem to make my dynamic hierarchy work. I have attached a code from my actual project. I can’t post the all the code. Parentchild.txt file contain the code to populate the parent child at the time of form loading Expanded contains the code of gridDataBoundGrid1_RowExpanded event. In this event I am trying to populate starting from ‘grandchild’ since I have already populated the parent-child initially. I am maintaining two ArrayList. One contain all the DataTable and other one contains all the ‘GridHierarchyLevel’ Following are the probles I am having #1 Grid doesn’t display correctly. After the ‘RowExpandeevent it shows me row with lots blank spaces between the rows. #2 if I collapse all the rows somehow then I don’t see any hierarchy after the pare-child. Basically child doesn’t have grandchild. ***************Foram load dsSummaryReport = new DataSet(); // Get report remote object IReportManager reportMgr = (IReportManager)Activator.GetObject (typeof(IReportManager),ConfigurationSettings.AppSettings["Host"]+"ReportManager.soap"); // Get report data dsSummaryReport = reportMgr.GetSummaryReportData(selectedYear,selectedRollupGroupList,selectedReportingStructure); // prepare the data tables and relation between them DataTable dtParent = dsSummaryReport.Tables["parent"]; DataTable dtChild = dsSummaryReport.Tables["child"]; dtList.Add(dtParent); dtList.Add(dtChild); #endregion #region Define the relation ship // level 1 dsSummaryReport.Relations.Add( dsSummaryReport.Tables["parent"].Columns["department_structure_no"], dsSummaryReport.Tables["child"].Columns["structure_parent_no"]); dsSummaryReport.Relations[0].RelationName = "Level1"; /*// level 2 DataColumn[] level2RollTypeColumns = {dsInitData.Tables["rollupList"].Columns["department_rollup_group_no"], dsInitData.Tables["rollupList"].Columns["department_rollup_no"]}; DataColumn[] level2RollCatColumns = {dsInitData.Tables["departmentList"].Columns["department_rollup_group_no"], dsInitData.Tables["departmentList"].Columns["department_rollup_no"]}; dsInitData.Relations.Add( level2RollTypeColumns, level2RollCatColumns); dsInitData.Relations[1].RelationName = "Level2"; */ /*// level 3 DataColumn[] level3RollCatColumns = {dsInitData.Tables["rollCatList"].Columns["company_no"], dsInitData.Tables["rollCatList"].Columns["type_no"],dsInitData.Tables["rollCatList"].Columns["category_no"]}; DataColumn[] level3DepartmentColumns = {dsInitData.Tables["departmentList"].Columns["company_no"], dsInitData.Tables["departmentList"].Columns["type_no"],dsInitData.Tables["departmentList"].Columns["category_no"]}; dsInitData.Relations.Add( level3RollCatColumns, level3DepartmentColumns); dsInitData.Relations[2].RelationName = "Level3";*/ #endregion #region Grid Formatting // start grid formatting this.gdbgMeritSummaryGrid.BeginUpdate(); this.gdbgMeritSummaryGrid.HScrollPixel = true; this.gdbgMeritSummaryGrid.ShowTreeLines = true; this.gridModel = this.gdbgMeritSummaryGrid.Model; this.gridBinder = this.gdbgMeritSummaryGrid.Binder; this.gdbgMeritSummaryGrid.Binder.ResetHierarchyLevels(); this.gdbgMeritSummaryGrid.DataSource = null; this.gdbgMeritSummaryGrid.DataMember = null; this.gdbgMeritSummaryGrid.Binder.GridBoundColumns.Clear(); this.gdbgMeritSummaryGrid.DataSource = null; this.gdbgMeritSummaryGrid.DataMember = "parent"; this.gdbgMeritSummaryGrid.DataSource = dsSummaryReport; this.gdbgMeritSummaryGrid.Model.BaseStylesMap["Header"].StyleInfo.Themed = false; this.gdbgMeritSummaryGrid.Model.BaseStylesMap["Header"].StyleInfo.Interior= new Syncfusion.Drawing.BrushInfo(Syncfusion.Drawing.GradientStyle.Vertical, System.Drawing.Color.FromArgb(((System.Byte)(203)), ((System.Byte)(199)), ((System.Byte)(184))), System.Drawing.Color.FromArgb(((System.Byte)(238)), ((System.Byte)(234)), ((System.Byte)(216)))); this.gdbgMeritSummaryGrid.EndUpdate(); hlRoot = gridBinder.RootHierarchyLevel; hlLevel1 = gridBinder.AddRelation("Level1"); //hlLevel2 = gridBinder.AddRelation("Level2"); //hlLevel3 = gridBinder.AddRelation("Level3"); this.hlRoot.RowStyle.BackColor = Color.Azure; this.hlRoot.RowStyle.Font.Bold = true; this.hlLevel1.RowStyle.BackColor = Color.PeachPuff; gridLevelList.Add(hlRoot); gridLevelList.Add(hlLevel1); //this.hlLevel2.RowStyle.BackColor = Color.LemonChiffon; //this.hlLevel3.RowStyle.BackColor = Color.PowderBlue; this.hlRoot.InternalColumns["name"].HeaderText = "Name"; this.hlRoot.InternalColumns["prior_salary"].HeaderText = "Prior\nTotal\nSalary"; this.hlRoot.InternalColumns["new_salary"].HeaderText = "New\nSalary"; this.hlRoot.InternalColumns["merit_pool_available"].HeaderText = "Merit Pool\n$ Available"; this.hlRoot.InternalColumns["merit_spent"].HeaderText = "Merit $\nSpent"; this.hlRoot.InternalColumns["per_diff"].HeaderText = "% Diff."; this.hlRoot.InternalColumns["performance_rating"].HeaderText = "Avg\nPerf.\nRating"; this.hlRoot.InternalColumns["filter"].HeaderText = " "; this.hlRoot.InternalColumns["merit_status_code"].HeaderText = "Merit sheet\nStatus"; this.gdbgMeritSummaryGrid.Model.RowHeights[0] = 94; this.gdbgMeritSummaryGrid.Model.RowHeights[1] = 0; *******************Event private void gdbgMeritSummaryGrid_RowExpanded(object sender, GridRowEventArgs e) { GridBoundRecordState state = this.gdbgMeritSummaryGrid.Binder.GetRecordStateAtRowIndex(e.RowIndex); try { // get child datatable count if ( dtList.Count < state.LevelIndex+3 && gridLevelList.Count < state.LevelIndex+3 ) { if (state.HasChildList && state.ChildList != null) { //string selectedRollupGroupList = "2063,2088"; string selectedRollupGroupList = ""; DataView dv1 = state.ChildList as DataView; int numRows1 = dv1.Count; string ss = ""; for(int row = 1; row <= numRows1; row++) { if (selectedRollupGroupList == "") selectedRollupGroupList= dv1[row-1][9].ToString(); else selectedRollupGroupList= selectedRollupGroupList + ","+dv1[row-1][9].ToString(); } string childLevelName = "child" + Convert.ToString((state.LevelIndex+2)); // Get report remote object IReportManager reportMgr = (IReportManager)Activator.GetObject (typeof(IReportManager),ConfigurationSettings.AppSettings["Host"]+"ReportManager.soap"); // Get report data DataTable dtChild = reportMgr.GetSummaryReportChildData(selectedRollupGroupList); dtChild.TableName = childLevelName; // prepare the data tables and relation between them dtList.Add(dtChild); dsSummaryReport.Tables.Add(dtChild); // save row state ArrayList alRowState = SaveOpenRows(e.RowIndex, state.ChildList.Count); this.gdbgMeritSummaryGrid.BeginUpdate(); this.gdbgMeritSummaryGrid.DataSource = null; this.gdbgMeritSummaryGrid.DataMember = ""; this.gdbgMeritSummaryGrid.Binder.ResetHierarchyLevels(); this.gdbgMeritSummaryGrid.DataSource = null; this.gdbgMeritSummaryGrid.DataMember = "parent"; this.gdbgMeritSummaryGrid.DataSource = dsSummaryReport; DataTable dtParentTable = (DataTable) dtList[state.LevelIndex+1]; DataRelation newChildRelation = new DataRelation(childLevelName, dtParentTable.Columns["department_structure_no"], dtChild.Columns["structure_parent_no"]); dsSummaryReport.Relations.AddRange(new DataRelation[]{newChildRelation}); this.gdbgMeritSummaryGrid.DataMember = "parent"; this.gdbgMeritSummaryGrid.DataSource = dsSummaryReport; for(int i = 0; i < gridLevelList.Count -1; ++i) { GridHierarchyLevel level = (GridHierarchyLevel) gridLevelList[i]; this.gdbgMeritSummaryGrid.Binder.AddRelation(level.Relation.Name); } GridHierarchyLevel currentLevel; currentLevel = this.gdbgMeritSummaryGrid.Binder.AddRelation(childLevelName); gridLevelList.Add(currentLevel); // formatting if (state.LevelIndex+2 == 2) currentLevel.RowStyle.BackColor = Color.LemonChiffon; else if (state.LevelIndex+2 == 3) currentLevel.RowStyle.BackColor = Color.PowderBlue; SetOpenRows(alRowState, e.RowIndex, state.ChildList.Count); this.gdbgMeritSummaryGrid.EndUpdate(); this.gdbgMeritSummaryGrid.Refresh(); } } } catch(Exception ex) { Cursor = Cursors.Arrow; bool rethrow = ExceptionPolicy.HandleException(ex, "Notify Policy"); if (rethrow) throw ex; } } Please do help me. regards,

AD Administrator Syncfusion Team June 7, 2005 09:51 PM UTC

Earlier I couldn’t attach the file. So i included the code. Atit

AD Administrator Syncfusion Team June 7, 2005 10:19 PM UTC

If you send a working project to support@syncfusion.com, I will try to look at it. Make sure you mention this forum thread in the subject line.

AD Administrator Syncfusion Team June 7, 2005 10:35 PM UTC

clay, It is not possible for me to take this portion out of my application. it is a big setup using Microsoft ft enterprise library if you could scan the code that would be great. thanks

AD Administrator Syncfusion Team June 8, 2005 01:02 AM UTC

I found the problem bigger problem. The following code is not working in ‘GDBG_RowExpanded event this.gdbgMeritSummaryGrid.Model.ColWidths[0] = 0; this.gdbgMeritSummaryGrid.Model.ColWidths[1] = 16; this.gdbgMeritSummaryGrid.Model.ColWidths[2] = 280; this.gdbgMeritSummaryGrid.Model.ColWidths[3] = 81; this.gdbgMeritSummaryGrid.Model.ColWidths[4] = 81; this.gdbgMeritSummaryGrid.Model.ColWidths[5] = 72; this.gdbgMeritSummaryGrid.Model.ColWidths[6] = 72; this.gdbgMeritSummaryGrid.Model.ColWidths[7] = 6; this.gdbgMeritSummaryGrid.Model.ColWidths[8] = 60; this.gdbgMeritSummaryGrid.Model.ColWidths[9] = 60; this.gdbgMeritSummaryGrid.Model.ColWidths[10] = 93; this.gdbgMeritSummaryGrid.Model.ColWidths[11] = 0; this.gdbgMeritSummaryGrid.Model.ColWidths[12] = 0; this.gdbgMeritSummaryGrid.Model.ColWidths[13] = 0; this.gdbgMeritSummaryGrid.Model.ColWidths[14] = 0; Please help me. Atit

AD Administrator Syncfusion Team June 8, 2005 08:28 AM UTC

If you are trying to do this code from Form.Load or some other place where the grid is not visible, you should also set: this.gridDataBoundGrid1.AllowResizeToFit = false; If you are trying to do this from RowExpanded, move your calls to this.gridDataBoundGrid1.Model.ColWidths under the grid.EndUpdate calls. This has to be done while the painting is not locked. A couple of other comments. Index 0 is the row header column, index 1 is the expand column, so your first column from your datasource is index 2 (and it shares a covered range with the expand column at index 1). So you need to take this into account as you set the widths. The second comment is that there is a single set of colwidths for the grid, and they apply to all levels.

AD Administrator Syncfusion Team June 8, 2005 04:54 PM UTC

Thanks to you clay, Almost everything is working now except one thing. At the very last level there is + signs within a box and if I click on it box doesn’t go away. Since it is the last level it shouldn’t show the +. I understand that this is a refresh/painting issue because if I minimize my form and then maximize it again then it dose come properly. Even if I scroll my grid horizontally or vertically then it works fine. Please do reply, Atit

AD Administrator Syncfusion Team June 8, 2005 06:24 PM UTC

Something to try. Handle the CellClick event. In it, if the e.ColIndex points to your expand cell (probably colindex = 1), then you can try calling grid.RefreshRange(GridRangeInfo.Cell(e.RowIndex, e.ColIndex), true);.

AD Administrator Syncfusion Team June 8, 2005 06:40 PM UTC

No it is not working. Anyway if it was working it was working only if I click on the cell. Is there anyway we can do some global refresh? Atit

AD Administrator Syncfusion Team June 9, 2005 01:03 AM UTC

You can try grid.RefreshRange(GridRangeInfo.Table(), true);

AD Administrator Syncfusion Team June 9, 2005 04:20 PM UTC

No it didn’t work. I guess I know the problem but I don’t the solution. Since my grid rows don’t have fixed level of hierarchy. So let’s say 3rd level is last level for some rows but for some rows it has child. So basically for some rows hierarchy goes up to 3rd level only while for other rows it goes up to 4,5, 6 level.. Does it make any sense to you? Atit

AD Administrator Syncfusion Team June 9, 2005 04:54 PM UTC

I have a bigger problem. Please do help. If first time my grid retrieve the records where there are 5 or more levels than if I try to retrieve the records where there are only 3 levels then my grid doesn’t display anything. And if I commented out the following code this.gdbgMeritSummaryGrid.ExpandAll(); this.gdbgMeritSummaryGrid.CollapseAll(); Then it works fine the only thing is that grid doesn’t get expanded & populated automatically. Atit

Live Chat Icon For mobile
Up arrow icon