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

How to Allow Add New Row in all self-referencing hierarchical level?

5 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
xjgs_xhj@163.com
Top achievements
Rank 1
xjgs_xhj@163.com asked on 12 Dec 2010, 07:57 AM
In GridView/self-referencing WinForms demo sample,how to 'AllowAddNewRow' in all hierarchical level?
Best Regards.

5 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 12 Dec 2010, 12:45 PM
Hello,

You need to add
this.radGridView1.AllowAddNewRow = true;

Example below
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace HierarchyGridObject_C
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.AllowAddNewRow = true;
  
            GridViewTemplate childTemplate  = new GridViewTemplate();
            childTemplate.DataSource = Data.TheChildren();
  
            this.radGridView1.DataSource = Data.TheParents();
  
            this.radGridView1.Templates.Add(childTemplate);
  
            GridViewRelation relation = new GridViewRelation();
            relation.ChildColumnNames.Add("ParentId");
            relation.ParentColumnNames.Add("Id");
            relation.ParentTemplate = this.radGridView1.MasterTemplate;
            relation.ChildTemplate = childTemplate;
            relation.RelationName = "ParentChildRelation";
  
            this.radGridView1.Relations.Add(relation);
  
              
        }
    }
}
  
public class Person 
{
    public Person()
    {
    }
  
    public Person (Int32 Id, String Name, Int32 ParentId)
    {this.Id = Id;
    this.Name = Name;
    this.ParentId = ParentId;
    }
  
    public string Name{ get; set; }
    public Int32 Id{ get; set; }
    public Int32 ParentId{ get; set; }
  
}
  
public class Data
{
    public static List<Person> TheParents()
    {
        List<Person> People = new List<Person>();
        People.Add(new Person(1, "Mary", 0));
        People.Add(new Person(2, "Richard", 0));
        People.Add(new Person(3, "Chris", 0));
        return People;
    }
  
    public static List<Person> TheChildren()
    {
        List<Person> People = new List<Person>();
        People.Add(new Person(4, "Little Mary", 1));
        People.Add(new Person(5, "Baby Mary", 1));
        People.Add(new Person(6, "teenager Chris", 3));
        return People;
    }
}

Hope that helps
Richard
0
xjgs_xhj@163.com
Top achievements
Rank 1
answered on 12 Dec 2010, 04:13 PM

I can't make my question clear in another thread(http://www.telerik.com/community/forums/winforms/gridview/how-to-add-nested-summaryrowitem-to-self-referencing-hierarchy-model-in-the-gridview-self-referencing-winforms-demo-sample.aspx). 
So I try to make it step by step.My first question actually is:
In the GridView/self-referencing WinForms demo sample,how to make
 "this.radGridView1.AllowAddNewRow = true" work in childTemplate.

In the demo sample,we don't need to declare 'childTemplate'.
private void Form1_Load(object sender, EventArgs e)
        {
            //   this.radGridView1.EnableGrouping = false;
            this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            // this.radGridView1.ReadOnly = true;
            this.radGridView1.DataSource = CreateDataSource();
            this.radGridView1.Relations.AddSelfReference(this.radGridView1.MasterTemplate, "ID", "ParentID");

            this.radGridView1.Columns["ID"].IsVisible = false;
            this.radGridView1.Columns["ParentID"].IsVisible = false;
            this.radGridView1.Columns["Size"].FormatString = "{0} MB";
        }

Best Regards.
0
Richard Slade
Top achievements
Rank 2
answered on 12 Dec 2010, 05:34 PM
Hello,

Apologies, I understand now what you mean. I don't think (as far as I'm aware) that this is possible. The reason is, is that the RadGridView in this case only contains the MasterGridViewTemplate, and no "ChildTemplates". therefore, you are only able to add rows to the master template. you can still add in the children, but they need to be added in the "New Row" at the top of the screen.

In order to have the new row, you need a child template too as per my exmaple above.

Hope that helps
Richard
0
xjgs_xhj@163.com
Top achievements
Rank 1
answered on 12 Dec 2010, 06:32 PM
That means it's impossible to add Grouping or SummaryRowItem to 'ChildTemplates'(of course they don't exit)?An alternative to accomplish this?
Self-referencing hierarchical is a cute feature and will be perfect to me if this can be done.
Best Regards.
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 12 Dec 2010, 06:55 PM
Hello,

As I mentioned, there are no templates other than the MasterTemplate. You can still drag columns to a group though. But as far as I'm aware, you cannot add a NewRow header to the child rows as there is no child template.
Hope that helps
Richard
Tags
GridView
Asked by
xjgs_xhj@163.com
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
xjgs_xhj@163.com
Top achievements
Rank 1
Share this question
or