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

GridView Hierarchy View Duplicate Child Row Issue

1 Answer 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 05 Mar 2013, 02:44 PM

I am creating a hierarchy grid using object relational data.  I am adding a GridViewRelation manually to link the two classes together.  The data loads correctly at first, but then selecting a child row will cause all child rows in that position to be duplicated and selected.

After initial data load, everything looks great.

(See dataload.png)


Select Child 2_1 and all first position children are selected.

(see select1.png)


Select Child 3_2 and now all second position children are selected, and the first position children are now duplicates of each other and read Child 4_1.

(see select2.png)


Here is the code:

namespace TestGrid
{
    public partial class Form1 : Form
    {
        private BindingList<MasterObject> data;
 
        public Form1()
        {
            InitializeComponent();
            SetupGrid();
        }
 
        private void SetupGrid()
        {
            LoadMasterTemplate(grid.MasterTemplate);
            GridViewTemplate childTemplate = new GridViewTemplate();
            LoadChildTemplate(childTemplate);
            grid.MasterTemplate.Templates.Add(childTemplate);
 
            GridViewRelation relation = new GridViewRelation(grid.MasterTemplate, childTemplate);
            relation.RelationName = "Children";
            relation.ChildColumnNames.Add("Children");
            grid.Relations.Add(relation);
        }
 
        private void LoadMasterTemplate(GridViewTemplate template)
        {
            template.Columns.Clear();
            template.EnableFiltering = false;
            template.AllowAddNewRow = false;
            template.ShowChildViewCaptions = false;
            template.AutoGenerateColumns = false;
            template.EnableGrouping = false;
 
            GridViewTextBoxColumn colNode = new GridViewTextBoxColumn("NodeDesc");
            colNode.HeaderText = "Node";
            colNode.Name = "Node";
            colNode.ReadOnly = true;
            template.Columns.Add(colNode);
 
            GridViewTextBoxColumn colName = new GridViewTextBoxColumn("Name");
            colName.HeaderText = "Name";
            colName.Name = "Name";
            template.Columns.Add(colName);
 
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
 
        private void LoadChildTemplate(GridViewTemplate template)
        {
            template.Columns.Clear();
            template.EnableFiltering = false;
            template.EnableGrouping = false;
            template.AllowAddNewRow = false;
            template.AutoGenerateColumns = false;
 
            GridViewTextBoxColumn colNode = new GridViewTextBoxColumn("NodeDesc");
            colNode.HeaderText = "Node";
            colNode.Name = "Node";
            colNode.ReadOnly = true;
            template.Columns.Add(colNode);
 
            GridViewTextBoxColumn colIP = new GridViewTextBoxColumn("Name");
            colIP.Name = "Name";
            colIP.HeaderText = "Name";
            template.Columns.Add(colIP);
 
            template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        }
 
        private void LoadData()
        {
            data = new BindingList<MasterObject>();
 
            for (int i = 1; i < 5; i++)
            {
                MasterObject m = new MasterObject();
                m.Name = "Master " + i;
                for (int x = 1; x < i; x++)
                {
                    ChildObject c = new ChildObject();
                    c.Name = "Child " + i + "_" + x;
                    m.Children.Add(c);
                }
                data.Add(m);
            }
 
            grid.DataSource = data;
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            // Load Data In Grid
            LoadData();
        }
 
        private void button2_Click(object sender, EventArgs e)
        {
            // Add Child to 1
            MasterObject m = data[0];
            ChildObject c = new ChildObject();
            c.Name = "Child " + "1_" + (m.Children.Count + 1);
            m.Children.Add(c);
        }
 
        private void button3_Click(object sender, EventArgs e)
        {
            // Add Child to 2
            MasterObject m = data[1];
            ChildObject c = new ChildObject();
            c.Name = "Child " + "2_" + (m.Children.Count + 1);
            m.Children.Add(c);
        }
    }
 
    public class MasterObject
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (name != value)
                {
                    name = value;
                }
            }
        }
 
        public string NodeDesc
        {
            get
            {
                return "MasterObject";
            }
        }
 
        private BindingList<ChildObject> children;
        public BindingList<ChildObject> Children
        {
            get
            {
                return children;
            }
            set
            {
                children = value;
            }
        }
 
        public MasterObject()
        {
            children = new BindingList<ChildObject>();
        }
    }
 
    public class ChildObject
    {
        private string name;
        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (name != value)
                {
                    name = value;
                }
            }
        }
 
        public string NodeDesc
        {
            get
            {
                return "ChildObject";
            }
        }
 
        public ChildObject() { }
    }
}

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 07 Mar 2013, 04:27 PM
Hi Randy,

Thank you for writing.

We are aware for this issue. We have already addressed it for the upcoming service pack, which will be available by the end of the month. I am not able to provide you with work around due to internal implementation of
RadGridView object-relational hierarchy. You can track the status of the issue here.

I hope that you find this information useful and that this time frame suits you.

Greetings,
Svett
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Tags
GridView
Asked by
Randy
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or