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

View Definition for a child template

13 Answers 254 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Deepak
Top achievements
Rank 1
Deepak asked on 21 Jan 2011, 03:27 PM
Hi,
        I get a blank template without column headers when I set the viewdefinition for a child template to

ColumnGroupsViewDefinition. When I use the same template on the MasterTemplate, it works fine. The code I use is

 

GridViewTemplate

 

 

gvChildTemplate = new GridViewTemplate();

 

gvChildTemplate.DataSource = _ds.Tables[1];

CustomizeChildTemplate(gvChildTemplate);

gvChildTemplate.ViewDefinition = _colGroupsView;

radGridView1.Templates.Add(gvChildTemplate);

 

 

GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);

 

relation.ChildTemplate = gvChildTemplate;

relation.RelationName =

 

"MeasureName";

 

relation.ParentColumnNames.Add(

 

"MeasureName");

 

relation.ChildColumnNames.Add(

 

"MeasureName");

 

radGridView1.Relations.Add(relation);



_colGroupsView is set using a different method and I can assure you, it is not null when the viewdefinition is set


Thanks
Deepak

13 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 05:41 PM
Hello,

As far as I know, RadGridView currently only supports assigning a ViewDefinition to the MasterTemplate.
I will however look into it and let you know if that's not the case.
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 21 Jan 2011, 05:46 PM
Hello,

I have tried this on an existing test project I have, and I'm pleased to say that it is supported. When you give the view the columns, you must make sure that you are defining the columns on the child template, not on the master template. Here is a full example

Designer File
namespace RadGridView_hierarchy_C
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components;
  
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
  
        #region Windows Form Designer generated code
  
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // radGridView1
            // 
            this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.radGridView1.Location = new System.Drawing.Point(0, 0);
            this.radGridView1.Name = "radGridView1";
            this.radGridView1.Size = new System.Drawing.Size(470, 384);
            this.radGridView1.TabIndex = 0;
            this.radGridView1.Text = "radGridView1";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(470, 384);
            this.Controls.Add(this.radGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
            this.ResumeLayout(false);
  
        }
  
        #endregion
  
        private Telerik.WinControls.UI.RadGridView radGridView1;
    }
}


Form1.cs
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;
using Telerik.WinControls.UI;
using Telerik.WinControls.RadControlSpy;
  
namespace RadGridView_hierarchy_C
{
    public partial class Form1 : Form
    {
          
  
        public Form1()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form1_Load);
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            creatingHierarchicalGridInUnboundMode();
        }
        public void creatingHierarchicalGridInUnboundMode()
        {
  
            DataTable parentData = new DataTable("MonitoringSymbolsParents");
            parentData.Columns.Add("ID", typeof(int));
            parentData.Columns.Add("Symbol", typeof(string));
            parentData.Columns.Add("Start Time", typeof(string));
            parentData.Columns.Add("End Time", typeof(string));
            parentData.Columns.Add("Depth", typeof(int));
            parentData.Columns.Add("Min Bid", typeof(string));
            parentData.Columns.Add("Max Bid", typeof(string));
  
            DataTable childData = new DataTable("MonitoringSymbolsChildren");
            childData.Columns.Add("ID", typeof(int));
            childData.Columns.Add("ParentID", typeof(int));
            childData.Columns.Add("Symbol", typeof(string));
            childData.Columns.Add("Start Time", typeof(string));
            childData.Columns.Add("End Time", typeof(string));
            childData.Columns.Add("Depth", typeof(int));
            childData.Columns.Add("Min Bid", typeof(string));
            childData.Columns.Add("Max Bid", typeof(string));
  
            this.radGridView1.DataSource = parentData;
  
            GridViewTemplate template = new GridViewTemplate();
            template.DataSource = childData;
            radGridView1.MasterTemplate.Templates.Add(template);
  
            GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);
            relation.ChildTemplate = template;
            relation.RelationName = "MyRelation";
            relation.ParentColumnNames.Add("ID");
            relation.ChildColumnNames.Add("ParentID");
            radGridView1.Relations.Add(relation);
  
            // parent data
            parentData.Rows.Add(1, "AUD/CAD Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 1, "1.0098", "1.01261");
            parentData.Rows.Add(2, "AUD/CCC Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 2, "1.00978", "1.01258");
            parentData.Rows.Add(3, "AUD/DDD Parent", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 3, "1.00961", "1.01258");
  
            // child data
            childData.Rows.Add(1, 1, "AUD/CAD Child", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 1, "1.0098", "1.01261");
            childData.Rows.Add(2, 1, "AUD/CAD Child", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 2, "1.00978", "1.01258");
            childData.Rows.Add(3, 1, "AUD/CAD Child", "12/20/2010 12:28:15 PM", "12/20/2010 3:28:15 PM", 3, "1.00961", "1.01258");
  
            this.radGridView1.MasterTemplate.Columns["ID"].IsVisible = true;
            this.radGridView1.Templates[0].Columns["ID"].IsVisible = true;
            this.radGridView1.Templates[0].Columns["ParentID"].IsVisible = true;
  
            this.radGridView1.Templates[0].ShowColumnHeaders = true;
            
            this.radGridView1.MasterTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.Templates[0].AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
  
  
            // Set all column widths
            foreach (GridViewColumn parentColumn in this.radGridView1.MasterTemplate.Columns)
            {
                if (parentColumn.IsVisible)
                
                    parentColumn.Width = 50;
                    parentColumn.MinWidth = 50;               
                }
            }
            foreach (GridViewColumn childColumn in this.radGridView1.Templates[0].Columns)
            {
                if (childColumn.IsVisible)
                {
                    childColumn.Width = 50;
                    childColumn.MinWidth = 50;
                }
            }
  
            ColumnGroupsViewDefinition view = new ColumnGroupsViewDefinition();
            view.ColumnGroups.Add(new GridViewColumnGroup("Bids"));
  
            view.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());
            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Templates[0].Columns["Min Bid"]); // must define as the child template column.
            view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Templates[0].Columns["Max Bid"]);
  
            this.radGridView1.Templates[0].ViewDefinition = view;
        }
  
  
    }
  
  
}

Note this line

view.ColumnGroups[0].Rows[0].Columns.Add(this.radGridView1.Templates[0].Columns["Min Bid"]);
the column added is the column in the child template. Not radgridView1.Columns["Min Bid"]

Hope that helps
Richard
0
Deepak
Top achievements
Rank 1
answered on 21 Jan 2011, 05:48 PM
Thank you Richard. I will try that out
0
Richard Slade
Top achievements
Rank 2
answered on 23 Jan 2011, 05:45 PM
No problem. Please remember to mark as answer if this was helpful, or let me know if you need more information
Richard
0
Deepak
Top achievements
Rank 1
answered on 24 Jan 2011, 12:48 PM
With the code that you gave me and pasting it word by word, the application freezes when I try to expand the parent node.

The code that I wrote doesnt freeze, but doesnt show any child rows...

 

 

private void AddChildTemplate()

 

{

 

 

GridViewTemplate gvChildTemplate = new GridViewTemplate();

 

gvChildTemplate.DataSource = _ds.Tables[1];

 

 

GridViewRelation relation = new GridViewRelation(radGridView1.MasterTemplate);

 

relation.ChildTemplate = gvChildTemplate;

relation.RelationName =

 

"Relation";

 

relation.ParentColumnNames.Add(

 

"MeasureName");

 

relation.ChildColumnNames.Add(

 

"MeasureName");

 

radGridView1.Relations.Add(relation);

CustomizeChildTemplate(gvChildTemplate);

gvChildTemplate.ShowColumnHeaders =

 

true;

 

radGridView1.Templates.Add(gvChildTemplate);

gvChildTemplate.ViewDefinition = _colGroupsView;

}

The child template is customized using the following code.

 

 

private void CustomizeChildTemplate(GridViewTemplate gvTemplate)

 

{

_colGroupsView =

 

new ColumnGroupsViewDefinition();

 

 

 

this._colGroupsView.ColumnGroups.Add(new GridViewColumnGroup("France"));

 

 

 

this._colGroupsView.ColumnGroups[0].Rows.Add(new GridViewColumnGroupRow());

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["MeasureName"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["3,1"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["4,1"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["5,1"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["3,2"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["4,2"]);

 

 

 

this._colGroupsView.ColumnGroups[0].Rows[0].Columns.Add(gvTemplate.Columns["5,2"]);

 

}

The child view without the view definition workd fine. However with the view definition set, it shows what is in the attachment


Thanks
Deepak



0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 12:53 PM
Hi Deepak,

Please can you confirm that you have tried my exmaple (not my code in your exmaple). And also can you confirm the version that you are using.
Many thanks
Richard
0
Deepak
Top achievements
Rank 1
answered on 24 Jan 2011, 12:56 PM
Hi Richard,
  I created a new form and pasted your designer and the code. So it is the exact copy of your example.
The telerik version I am using is 2010.2.10.806 and the .net runtime is .net 4.0

Thanks
Deepak
0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 01:01 PM
Hi again,

Thanks for writing back with that information.I'm also using .NET 4.0, but I am using the latest version of the RadControls for WinForms. (Q3 2010 SP1).
Unfortunatly, I don't have the older version that you are using, but this code is working under the latest version.

I'd suggest upgrading to the latest if possible. There are many enhancements, fixes and new areas of functionality that you can take advantage of by upgrading and you will notice the difference straight away.

If  you have any other questions or comments, please do let me know
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 01:15 PM
Deepak,

If you would like to post a full sample I'll see if I can get it working for you, but at the moment, it seems to be an issue with you running the older version. If you do post the full code, please use the format code block to add the code.
thanks
Richard
0
Deepak
Top achievements
Rank 1
answered on 24 Jan 2011, 02:50 PM
Hello Richard,
 I am installing the latest version.... I will post the code if not successful with the latest version.

Thanks
Deepak
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 03:03 PM
Ok, fantastic. I think you will get on fine with the latest version.
Regards,
Richard
0
Deepak
Top achievements
Rank 1
answered on 24 Jan 2011, 03:07 PM
Hi Richard,
 My code works with the new version too...  Thanks for everything

Deepak
0
Richard Slade
Top achievements
Rank 2
answered on 24 Jan 2011, 03:09 PM
That's good news. Glad that helped. Please remember to mark as answer.
All the best
Richard
Tags
GridView
Asked by
Deepak
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Deepak
Top achievements
Rank 1
Share this question
or