RadGridView, Hierarchical Relationship doesn't work

4 posts, 1 answers
  1. Erwin
    Erwin avatar
    3 posts
    Member since:
    Jul 2015

    Posted 03 Jul 2015 Link to this post

    I have created a hierarchical relationship in a RadGridView. But the relationship doesn't work. I can't show the detail information. What do I do wrong?

     

    This is the source:

    private void OpenConfigurations()
    {
      bsConfigurations.DataSource = Db.Configurations.Where(c => c.Active == true && c.CompanyId == CurrentCompany.CompanyId).Select(c => c).OrderBy(c => c.Name);
      bsConfigurationContracts.DataSource = Db.ConfigurationContracts.Where(c => c.Contract.InsurranceId == CurrentCompany.CompanyId).Select(c =>
    c).OrderBy(c => c.Contract.Name);

      GridViewRelation gvrConfigurations = new GridViewRelation();

      gvrConfigurations.ChildColumnNames.Add("ConfigurationId");

      gvrConfigurations.ChildTemplate = this.gridViewTemplate1;

      gvrConfigurations.ParentColumnNames.Add("ConfigurationId");

      gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;

      gvConfiguration.Relations.Add(gvrConfigurations);
    }

    In the designer: 
    this.gridViewTemplate1.AllowAddNewRow = false;
    gridViewTextBoxColumn1.EnableExpressionEditor = false;
    gridViewTextBoxColumn1.FieldName = "Contract.Name";
    gridViewTextBoxColumn1.HeaderText = "Name";
    gridViewTextBoxColumn1.Name = "colName";
    gridViewTextBoxColumn1.Width = 250;
    gridViewTextBoxColumn2.EnableExpressionEditor = false;
    gridViewTextBoxColumn2.FieldName = "ConfigurationId";
    gridViewTextBoxColumn2.HeaderText = "ConfigurationId";
    gridViewTextBoxColumn2.IsVisible = false;
    gridViewTextBoxColumn2.Name = "colConfigurationId";

    this.gridViewTemplate1.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn1, gridViewTextBoxColumn2 });
    this.gridViewTemplate1.DataSource = this.bsConfigurationContracts;
    //
    // gvConfiguration
    //
    this.gvConfiguration.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(233)))), ((int)(((byte)(240)))), ((int)(((byte)(249)))));
    this.gvConfiguration.Cursor = System.Windows.Forms.Cursors.Default;
    this.gvConfiguration.Dock = System.Windows.Forms.DockStyle.Fill;
    this.gvConfiguration.Font = new System.Drawing.Font("Segoe UI", 8.25F);
    this.gvConfiguration.ForeColor = System.Drawing.Color.Black;
    this.gvConfiguration.ImeMode = System.Windows.Forms.ImeMode.NoControl;
    this.gvConfiguration.Location = new System.Drawing.Point(0, 30);
    //
    //
    //
    this.gvConfiguration.MasterTemplate.AllowAddNewRow = false;
    this.gvConfiguration.MasterTemplate.AutoGenerateColumns = false;
    gridViewTextBoxColumn3.EnableExpressionEditor = false;
    gridViewTextBoxColumn3.FieldName = "Name";
    gridViewTextBoxColumn3.HeaderText = "Name";
    gridViewTextBoxColumn3.Name = "colName";
    gridViewTextBoxColumn3.SortOrder = Telerik.WinControls.UI.RadSortOrder.Ascending;
    gridViewTextBoxColumn3.Width = 250;
    gridViewTextBoxColumn4.EnableExpressionEditor = false;
    gridViewTextBoxColumn4.FieldName = "ConfigurationId";
    gridViewTextBoxColumn4.HeaderText = "ConfigurationId";
    gridViewTextBoxColumn4.IsVisible = false;
    gridViewTextBoxColumn4.Name = "colConfigurationId";
    this.gvConfiguration.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] { gridViewTextBoxColumn3, gridViewTextBoxColumn4 });
    this.gvConfiguration.MasterTemplate.DataSource = this.bsConfigurations;
    sortDescriptor1.PropertyName = "colName";
    this.gvConfiguration.MasterTemplate.SortDescriptors.AddRange(new Telerik.WinControls.Data.SortDescriptor[] { sortDescriptor1 });
    this.gvConfiguration.MasterTemplate.Templates.AddRange(new Telerik.WinControls.UI.GridViewTemplate[] { this.gridViewTemplate1 });
    this.gvConfiguration.Name = "gvConfiguration";
    this.gvConfiguration.RightToLeft = System.Windows.Forms.RightToLeft.No;
    this.gvConfiguration.ShowGroupPanel = false;
    this.gvConfiguration.Size = new System.Drawing.Size(1098, 72);
    this.gvConfiguration.TabIndex = 4;
    this.gvConfiguration.Text = "radGridView1";
    this.gvConfiguration.CellDoubleClick += new Telerik.WinControls.UI.GridViewCellEventHandler(this.gvConfiguration_CellDoubleClick);

  2. Erwin
    Erwin avatar
    3 posts
    Member since:
    Jul 2015

    Posted 05 Jul 2015 in reply to Erwin Link to this post

    Sorry I use VS2013 Prof., WinForms as UI and LINQ to SQL as datasource.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 07 Jul 2015 Link to this post

    Hello Erwin,

    Thank you for writing.

    When creating a relation, you should specify the names of the grid view columns, not the field names:
    GridViewRelation gvrConfigurations = new GridViewRelation();
    gvrConfigurations.ChildColumnNames.Add("colConfigurationId");
    gvrConfigurations.ChildTemplate = this.gridViewTemplate1;
    gvrConfigurations.ParentColumnNames.Add("colConfigurationId");
    gvrConfigurations.ParentTemplate = this.gvConfiguration.MasterTemplate;
    gvConfiguration.Relations.Add(gvrConfigurations);

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  5. Erwin
    Erwin avatar
    3 posts
    Member since:
    Jul 2015

    Posted 07 Jul 2015 in reply to Stefan Link to this post

    Thanks for your answer. Sorry. But I found the answer jet. This was what I did doing wrong...
Back to Top