This is a migrated thread and some comments may be shown as answers.

unknown number of heirarchy

3 Answers 42 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rafia Tapia
Top achievements
Rank 1
Rafia Tapia asked on 21 May 2009, 11:21 AM
Hi,
I have a object called ObjNodeProperties that is defined as follow

 

public struct ObjNodeProperty

 

 

{

 

private string _PropertyName;

 

 

 

private string _PropertyType;

 

 

 

private string _PropertyValue;

 

 

 

private List<ObjNodeProperty> _InternalValues;
}
I am trying to bind a List<ObjNodeProperty> but what I want that for each _internalValues and even within each _internalValues it should create a childe template. There is no restriction on how many level deep a particular ObjNodeProperty object could be. Also on the grid I only want two columns of _PropertyName and _PropertyValue. How do I restrict the binding to only those two column.

Thanks for the help

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 22 May 2009, 07:21 AM
Hi Rafia Tapia,

Please see your related support ticket.

Kind regards,
Julian Benkov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rafia Tapia
Top achievements
Rank 1
answered on 22 May 2009, 06:02 PM

I was able to figure out my solution but I could not use binding. I am putting the solution here for anybody who is interesting

 

I had to make a slight modification to my data stucture so that the parent, child relation could be establish for the grid. Below is my data structure

 

public struct ObjProperty

{

        private int _PropertyID;

        private int _ParentID;

        private string _PropertyName;

        private string _PropertyValue;

        private List<ObjProperty> _InternalValues;

}

 

In my form load event, I am creating the columns for the master template like this

 

PropertyDisplayGrid.MasterGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

PropertyDisplayGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("PropertyName"){HeaderText="Property Name", HeaderTextAlignment=ContentAlignment.MiddleCenter});

PropertyDisplayGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("PropertyValue") { HeaderText = "Property Value", HeaderTextAlignment = ContentAlignment.MiddleCenter});

PropertyDisplayGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("PropertyID") { IsVisible = false });

PropertyDisplayGrid.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("PropertyParentID") { IsVisible = false });

 

Then finally on a click event I am populating the grid

 

InsertPropertyInGrid(MyPropCollection, PropertyDisplayGrid.MasterGridViewTemplate);

 

where the InsertPropertyInGrid is implemented as follow

 

private void InsertPropertyInGrid(List<ObjProperty> propColl, GridViewTemplate propgrid)

                {

            foreach (ObjProperty prop in propColl)

            {

                propgrid.Rows.Add(new object[] { prop.PropertyName, prop.PropertyValue, prop.PropertyID, prop.ParentID });

                if (prop._InternalValues != null)

                {

                    GridViewTemplate _childtemplate = new GridViewTemplate(){AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill};

                    _childtemplate.Columns.Add(new GridViewDataColumn("PropertyName") { HeaderText = "Property Name", HeaderTextAlignment = ContentAlignment.MiddleCenter});

                    _childtemplate.Columns.Add(new GridViewDataColumn("PropertyValue") { HeaderText = "Property Value", HeaderTextAlignment = ContentAlignment.MiddleCenter});

                    _childtemplate.Columns.Add(new GridViewDataColumn("PropertyID") { IsVisible = false });

                    _childtemplate.Columns.Add(new GridViewDataColumn("PropertyParentID") { IsVisible = false });

                    propgrid.ChildGridViewTemplates.Add(_childtemplate);

                    GridViewRelation relation = new GridViewRelation(propgrid) { ChildTemplate = _childtemplate, RelationName = "InternalValues" };

                    relation.ParentColumnNames.Add("PropertyID");

                    relation.ChildColumnNames.Add("PropertyParentID");

                    PropertyDisplayGrid.Relations.Add(relation);

                    InsertPropertyInGrid(prop._InternalValues, _childtemplate);

                }

            }

        }

0
Nikolay
Telerik team
answered on 27 May 2009, 02:02 PM
Hello Rafia Tapia,

I am glad to hear that you found the solution to your scenario. Thank you for sharing it with the community. If you have other question, feel free to contact us.

Regards,
Nikolay
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Rafia Tapia
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Rafia Tapia
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or