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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridHierarchyLevel.AddRelation

Thread ID:

Created:

Updated:

Platform:

Replies:

15166 Jun 13,2004 03:30 PM UTC Jun 15,2004 03:13 AM UTC Windows Forms 5
loading
Tags: GridControl
Herman Muys
Asked On June 13, 2004 03:30 PM UTC

Hello, I''m trying to find a generic solution for navigating a hierarchic table with a GridDataBoundGrid. In this table there exist a ''primary key'' field, and a ''parent'' key field. The parent key points primary key into the same table. I try to define a relation between a primary key and all child records having this same parent key. After this I create a new GridHierarchyLevel by adding a new relation to the gridModelDataBinder. (addRelation(..)) If I presume the depth of my hierarchic table and if I create those relations in advance in the form_load event, all goes well. If I try to create those datarelations dynamically in the GridRowExpanding event, something goes wrong: protected virtual void GridRowExpanding(object sender, GridRowEventArgs e) { ... GridDataBoundGrid grid = (GridDataBoundGrid) sender; GridBoundRecordState rs = grid.Binder.GetRecordStateAtRowIndex(e.RowIndex); GridHierarchyLevel ghl = grid.Binder.GetHierarchyLevel(rs.LevelIndex); level = rs.LevelIndex ; if (rs.LevelIndex + 2 >= grid.Binder.HierarchyLevelCount) { grid.BeginUpdate(); try { sql = "Select pkey, code, text ,parent, "+ (level+2).ToString ()+ " as levl from hm_icd9_tab where icd9_key=0"; da.SelectCommand.CommandText = sql da.Fill (ds, "Tabulation" +(level+2).ToString () ); } catch (Exception exp) { System.Diagnostics.Trace.WriteLine ( exp.Message ); } try { DataRelation r; DataTable t1 = ds.Tables["Tabulation"+(level+2).ToString()]; DataTable t2 = ds.Tables["Tabulation"+(level+3).ToString()]; r = ds.Relations.Add( t1.Columns["PKEY"],t2.Columns["PARENT"]); if (r != null) { r.RelationName = "LEVEL"+(level+2).ToString(); } } catch (Exception exp) { System.Diagnostics.Trace.WriteLine ( exp.Message ); } try { GridHierarchyLevel childLevel = grid.Binder.AddRelation("LEVEL"+(level+2).ToString()); <== FAILS if (childLevel != null) { childLevel.ShowHeaders = false; childLevel.LayoutColumns( new string[] {"TEXT", "CODE","PKEY","LEVL" }); ... } } catch (Exception exp) { System.Diagnostics.Trace.WriteLine ( exp.Message ); } grid.EndUpdate(); } ... } I can add this relation to the dataset, but calling gridModelDataBinder.AddRelation with the newly created relation string fails. Tracing the source, learns that in GridHierarchyLevel.AddRelation the PropertyDescriptorCollection doesn''t contains the newly created relation PropertyDescriptor. Any idea how to force this PropertyDescriptor? Thanx Herman

Herman Muys
Replied On June 14, 2004 09:21 AM UTC

Sorry, cutting and pasting a text doesnt seems a good idea for the readability. I''m trying to add a hierarchic level in the gridrowexpanding event handler of a databound hierarchy grid. Herefore I create in this handler a new datarelation in my dataset. Then I try to add a new GridHierarchycLevel by calling the AddRelation method of the grid binder. This call returns nothing. Tracing the code learns that in the propertyDescriptionCollection of current GridHierchyLevel no ''relation'' propertydescription exist, describing the newly created dataset relation . Any idea''s?

Administrator [Syncfusion]
Replied On June 14, 2004 03:36 PM UTC

I think the problem is that a GridHierarchyLevel keeps a copy of the original PropertyDescriptorCollection of the underlying datasource. The only way to reinitialize that GridHierarchyLevel is to call InitializeColumns. Not sure if after you get that working if there are other issues. You might end up having to reset all relations (ResetHierarchyLevels) and reinitialize the grid completely (add all relations again).

Herman Muys
Replied On June 14, 2004 04:10 PM UTC

I did try to call InitializeColumns and ResetHierarchyLevel. Without success however. >I think the problem is that a GridHierarchyLevel keeps a copy of the original PropertyDescriptorCollection of the underlying datasource. > >The only way to reinitialize that GridHierarchyLevel is to call InitializeColumns. > >Not sure if after you get that working if there are other issues. You might end up having to reset all relations (ResetHierarchyLevels) and reinitialize the grid completely (add all relations again). > >

Administrator [Syncfusion]
Replied On June 14, 2004 08:02 PM UTC

I may be missing what you want to do, but would it be possible to go ahead and create all the relations and hierarchy levels, but not actually populate the tables involved until the RowsExpanding event? Would this serve your purpose of dynamically populating the child levels?

Herman Muys
Replied On June 15, 2004 03:13 AM UTC

Ok, I can live with this. Thanks Herman

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;