Hi,
I recently read that self-referencing hierarchy is now supported by the radGridView. Unfortunately, I have been unable to locate any demos, tutorials, or sample code to look at. Is this information available?
Here is my current code that I'm working with:
| private void SetupElementsGrid() |
| { |
| radGvElements.Columns.Clear(); |
| radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementID")); |
| radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ProtocolTemplateID")); |
| radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ParentElementID")); |
| radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementNumber")); |
| radGvElements.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("ElementDesc")); |
| radGvElements.Columns["ElementID"].IsVisible = false; |
| radGvElements.Columns["ProtocolTemplateID"].IsVisible = false; |
| radGvElements.Columns["ParentElementID"].IsVisible = false; |
| radGvElements.Columns["ElementNumber"].HeaderText = "Element Number"; |
| radGvElements.Columns["ElementDesc"].HeaderText = "Element Description"; |
| radGvElements.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; |
| GridViewTemplate childTemplate = new GridViewTemplate(); |
| childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementID")); |
| childTemplate.Columns.Add(new GridViewTextBoxColumn("ProtocolTemplateID")); |
| childTemplate.Columns.Add(new GridViewTextBoxColumn("ParentElementID")); |
| childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementNumber")); |
| childTemplate.Columns.Add(new GridViewTextBoxColumn("ElementDesc")); |
| //childTemplate.Columns["ElementID"].IsVisible = false; |
| //childTemplate.Columns["ProtocolTemplateID"].IsVisible = false; |
| //childTemplate.Columns["ParentElementID"].IsVisible = false; |
| //childTemplate.Columns["ElementNumber"].HeaderText = "Element Number"; |
| //childTemplate.Columns["ElementDesc"].HeaderText = "Element Description"; |
| childTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill; |
| if(radGvElements.MasterGridViewTemplate.ChildGridViewTemplates.Count == 0) |
| { |
| radGvElements.MasterGridViewTemplate.ChildGridViewTemplates.Add(childTemplate); |
| } |
| GridViewRelation relation = new GridViewRelation(radGvElements.MasterGridViewTemplate); |
| relation.ChildTemplate = childTemplate; |
| relation.RelationName = "ParentChild"; |
| relation.ParentColumnNames.Add("ElementID"); |
| relation.ChildColumnNames.Add("ParentElementID"); |
| radGvElements.Relations.Add(relation); |
| ProtocolTemplate = (ProtocolTemplate)ProtocolTemplatesBindingSource.CurrencyManager.List[ProtocolTemplatesBindingSource.CurrencyManager.Position]; |
| ElementsBindingSource.DataSource = ProtocolTemplate.Elements; |
| radGvElements.DataSource = ElementsBindingSource; |
| radGvElements.DataSource = ElementsBindingSource; |
| childTemplate.DataSource = ElementsBindingSource; |
| } |
Sample data would look like this:
ElementID -- ProtocolTemplateID -- ParentElementID -- ElementNumber -- ElementDesc
1 -- 1 -- 1 -- 1.0 -- ParentLevel1
2 -- 1 -- 1 -- 1.1 -- ChildLevel1
3 -- 1 -- 1 -- 1.2 -- ChildLevel2
4 -- 1 -- 4 -- 2.0 -- ParentLevel2
With my current code, this displays as:
Row 1
-- Row1
-- Row2
-- Row3
Row 2
Row 3
Row 4
-- Row 4
It should be:
Row 1
-- Row 2
-- Row 3
Row 4
Also, another problem is with the portion of code I have commented out. This code causes a NullReferenceException error to be thrown and I don't know why.
If anyone could help me out with the above code, or even point me in the direction of some reading material, I would be very grateful.
Thanks,
Robert
