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

Refresh in data binding issue.

3 Answers 393 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raymond
Top achievements
Rank 1
Raymond asked on 22 Nov 2010, 10:05 AM

Hi,

Description:

I'm facing refreshing issue when using rad grid view (below I've attached code snippet you can use to reproduce it).

Generally in the described example I have two collections in parent - child relation binded to grid view and one button that adds new object to child collection.

Problem:

When first node in grid is expanded and have no children and I add a new child, it won't appear in grid view, even that node is marked as expanded (untitled.png). To see it I have to collapse and expand it again (untitled2.png) .

It's very imported for me to make it working correctly.

Code:

001.using System;
002.using System.Collections.Generic;
003.using System.ComponentModel;
004.using System.Data;
005.using System.Drawing;
006.using System.Linq;
007.using System.Text;
008.using System.Windows.Forms;
009.using Telerik.WinControls.UI;
010.  
011.namespace WindowsFormsApplication1
012.{
013.    public partial class Form1 : Form
014.    {
015.  
016.        public class A
017.        {
018.            public int Id
019.            { get; set; }
020.  
021.            public string Name
022.            { get; set; }
023.  
024.            public string Value
025.            { get; set; }
026.        }
027.  
028.        public class B
029.        {
030.            public int ParentId
031.            { get; set; }
032.  
033.            public string Value
034.            { get; set; }
035.        }
036.  
037.  
038.        BindingList<A> parentList;
039.  
040.        BindingList<B> childList;
041.  
042.        GridViewTemplate childTemplate;
043.  
044.        public Form1()
045.        {
046.            InitializeComponent();
047.  
048.            radGridView1.ReadOnly = true;
049.  
050.            parentList = new BindingList<A>(new List<A>(new A[] { 
051.            new A() { Id = 1, Name = "name 1", Value = "value 1" },
052.            new A() { Id = 2, Name = "name 2", Value = "value 2" },
053.            }));
054.  
055.            childList = new BindingList<B>(new List<B>(new B[] {
056.            //new B() { ParentId = 1 , Value = "b value 1"},
057.            //new B() { ParentId = 1 , Value = "b value 2"},
058.            new B() { ParentId = 2 , Value = "b value 3"},
059.            new B() { ParentId = 2 , Value = "b value 4"}
060.            }));
061.  
062.  
063.            childTemplate = AddMonitorPackageItemsTemplate();
064.            CreateRelation(childTemplate);
065.            radGridView1.DataSource = bindingSource1;
066.  
067.            bindingSource1.DataSource = parentList;
068.            bindingSource2.DataSource = childList;
069.  
070.        }
071.  
072.        void CreateRelation(GridViewTemplate childTemplate)
073.        {
074.            GridViewRelation monitoredItemToCSRelation = new GridViewRelation(radGridView1.MasterTemplate);
075.            monitoredItemToCSRelation.ChildTemplate = childTemplate;
076.            monitoredItemToCSRelation.RelationName = "childTemplateRelation";
077.  
078.            monitoredItemToCSRelation.ParentColumnNames.Add("Id");
079.            monitoredItemToCSRelation.ChildColumnNames.Add("ParentId");
080.            radGridView1.Relations.Add(monitoredItemToCSRelation);
081.        }
082.  
083.        GridViewTemplate AddMonitorPackageItemsTemplate()
084.        {
085.            GridViewTemplate monitoredPackageItemTemplate = new GridViewTemplate();
086.            monitoredPackageItemTemplate.DataSource = bindingSource2;
087.            radGridView1.Templates.Add(monitoredPackageItemTemplate);
088.            return monitoredPackageItemTemplate;
089.        }
090.  
091.        private void button1_Click(object sender, EventArgs e)
092.        {
093.            childList.Add(new B() { ParentId = 1, Value = Guid.NewGuid().ToString() });
094.        }
095.  
096.  
097.        /// <summary>
098.        /// Required designer variable.
099.        /// </summary>
100.        private System.ComponentModel.IContainer components = null;
101.  
102.        /// <summary>
103.        /// Clean up any resources being used.
104.        /// </summary>
105.        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
106.        protected override void Dispose(bool disposing)
107.        {
108.            if (disposing && (components != null))
109.            {
110.                components.Dispose();
111.            }
112.            base.Dispose(disposing);
113.        }
114.  
115.        #region Windows Form Designer generated code
116.  
117.        /// <summary>
118.        /// Required method for Designer support - do not modify
119.        /// the contents of this method with the code editor.
120.        /// </summary>
121.        private void InitializeComponent()
122.        {
123.            this.components = new System.ComponentModel.Container();
124.            this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
125.            this.bindingSource2 = new System.Windows.Forms.BindingSource(this.components);
126.            this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
127.            this.button1 = new System.Windows.Forms.Button();
128.            ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
129.            ((System.ComponentModel.ISupportInitialize)(this.bindingSource2)).BeginInit();
130.            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
131.            this.radGridView1.SuspendLayout();
132.            this.SuspendLayout();
133.            // 
134.            // radGridView1
135.            // 
136.            this.radGridView1.Controls.Add(this.button1);
137.            this.radGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
138.            this.radGridView1.Location = new System.Drawing.Point(0, 0);
139.            this.radGridView1.Name = "radGridView1";
140.            this.radGridView1.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
141.            // 
142.            // 
143.            // 
144.            this.radGridView1.RootElement.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
145.            this.radGridView1.Size = new System.Drawing.Size(649, 328);
146.            this.radGridView1.TabIndex = 0;
147.            this.radGridView1.Text = "radGridView1";
148.            // 
149.            // button1
150.            // 
151.            this.button1.Location = new System.Drawing.Point(562, 3);
152.            this.button1.Name = "button1";
153.            this.button1.Size = new System.Drawing.Size(75, 23);
154.            this.button1.TabIndex = 0;
155.            this.button1.Text = "button1";
156.            this.button1.UseVisualStyleBackColor = true;
157.            this.button1.Click += new System.EventHandler(this.button1_Click);
158.            // 
159.            // Form1
160.            // 
161.            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
162.            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
163.            this.ClientSize = new System.Drawing.Size(649, 328);
164.            this.Controls.Add(this.radGridView1);
165.            this.Name = "Form1";
166.            this.Text = "Form1";
167.            ((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
168.            ((System.ComponentModel.ISupportInitialize)(this.bindingSource2)).EndInit();
169.            ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
170.            this.radGridView1.ResumeLayout(false);
171.            this.ResumeLayout(false);
172.  
173.        }
174.  
175.        #endregion
176.  
177.        private System.Windows.Forms.BindingSource bindingSource1;
178.        private System.Windows.Forms.BindingSource bindingSource2;
179.        private Telerik.WinControls.UI.RadGridView radGridView1;
180.        private System.Windows.Forms.Button button1;
181.    }
182.}

Regards.

3 Answers, 1 is accepted

Sort by
0
Julian Benkov
Telerik team
answered on 24 Nov 2010, 02:01 PM
Hello Raymond,

We found some issues with the automatic inner level refresh and the lazy loading mechanism. We will address them in Q3 2010 SP1 scheduled for the middle of December. Currently, you can refresh the second level using the following code snippet:

private void radButton1_Click(object sender, EventArgs e)
{
    childList.Add(new B() { ParentId = 1, Value = Guid.NewGuid().ToString() });
    this.radGridView1.MasterTemplate.Refresh();
    foreach (GridViewRowInfo row in this.radGridView1.ChildRows)
    {
        row.IsExpanded = true;
    }
}

Thank you for the reported issue. Your Telerik points have been updated.

Sincerely yours,
Julian Benkov
the Telerik team
Get started with RadControls for WinForms with numerous videos and detailed documentation.
0
Raymond
Top achievements
Rank 1
answered on 17 Dec 2010, 02:14 PM

I've just updated libs to the newest release and it's even worse than before...

Please try out the same example I've provided before ...

1) click on plus to expand when there is nothing below node (no children)

2) click on the button to add children 

3) try to expand the node again

It's frozen and don't respond to users action at all - you won't be able to expand it any more.

0
Accepted
Julian Benkov
Telerik team
answered on 22 Dec 2010, 05:49 PM
Hi Raymond,

Please find the answer to your question in the support ticket that concerns the same topic.

All the best,

Julian Benkov
the Telerik team

 

Check out the Q1 2011 Roadmap for Telerik Controls for Windows Forms.
Tags
GridView
Asked by
Raymond
Top achievements
Rank 1
Answers by
Julian Benkov
Telerik team
Raymond
Top achievements
Rank 1
Share this question
or