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

Grid scrolling to bottom row after a datasource refresh

11 Answers 856 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Fred
Top achievements
Rank 1
Fred asked on 13 Oct 2010, 03:39 PM
Hello,

I've got a problem with the GridView I cannot explain, when I reassign the datasources for a hierarchic grid after having selected a child, the grid will always scroll to the bottom on trying to select children after the datasource is reset. It seems like it's internal offset list has been corrupted or something like that. I've made the most simple test case, so hopefully someone can reproduce this problem and tell me what I'm doing wrong. I've seen examples just reassign the datasource so that should be no problem, but maybe I'm missing some step. I did see someone reference this behaviour in another post Errors clicking on childrows of heirarchical gridview on the forum (the case 2), but no proposed solution was given. So I'm kinda stuck and any help would be very much appreciated.

TestGridForm2.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.UI;
using Telerik.WinControls.Enumerations;
 
namespace RadGridViewProblems
{
    /*
     * Demonstate a gridview problem when setting the datasource a second time (or more) when a child row is clicked
     * the grid scrolls to the bottom, reason/workaround: unknown
     */
 
    public partial class TestGridForm2 : RadForm
    {
        public TestGridForm2()
        {
            InitializeComponent();
 
            this.Load += new EventHandler(FormLoaded);
        }
 
        private void FormLoaded(object sender, EventArgs e)
        {
            //testGridView.ReadOnly = true;
            testGridView.AutoGenerateColumns = true;
 
            childGridViewTemplate = new GridViewTemplate();
            childGridViewTemplate.AutoGenerateColumns = true;
 
            testGridView.MasterTemplate.ShowRowHeaderColumn = true;
            childGridViewTemplate.ShowRowHeaderColumn = false;
 
            testGridView.MasterTemplate.Templates.Add(childGridViewTemplate);
 
            GridViewRelation relation = new GridViewRelation(testGridView.MasterTemplate);
            relation.ChildTemplate = childGridViewTemplate;
            relation.RelationName = "ParentChildren";
            relation.ParentColumnNames.Add("id");
            relation.ChildColumnNames.Add("parent_id");
 
            testGridView.Relations.Add(relation);
 
            LoadData();
        }
 
        private void LoadData()
        {
            /*childGridViewTemplate.DataSource = null;
            testGridView.DataSource = null;*/
 
            List<MyParentClass> myParentList = new List<MyParentClass>();
            for(int i=1; i<=100; i++)
            {
                myParentList.Add(new MyParentClass() { id = i, name = i.ToString(), info = "blabla" });
            }
 
            List<MyChildClass> myChildList = new List<MyChildClass>();
            Random random = new Random(1);
            for(int i=1; i<=300; i++)
            {
                myChildList.Add(new MyChildClass() { parent_id = random.Next(1,100), id = i, name = i.ToString(), info = "blabla" });
            }
 
            childGridViewTemplate.DataSource = myChildList;
            testGridView.DataSource = myParentList;
        }
 
        private void resetButton_Click(object sender, EventArgs e)
        {
            LoadData();
        }
 
        private GridViewTemplate childGridViewTemplate;
    }
 
}


TestGridForm2.Designer.cs
namespace RadGridViewProblems
{
    partial class TestGridForm2
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
        /// <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.testGridView = new Telerik.WinControls.UI.RadGridView();
            this.resetButton = new Telerik.WinControls.UI.RadButton();
            ((System.ComponentModel.ISupportInitialize)(this.testGridView)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.resetButton)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
            this.SuspendLayout();
            //
            // testGridView
            //
            this.testGridView.Dock = System.Windows.Forms.DockStyle.Fill;
            this.testGridView.Location = new System.Drawing.Point(0, 0);
            this.testGridView.Name = "testGridView";
            this.testGridView.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
            //
            //
            //
            this.testGridView.RootElement.Padding = new System.Windows.Forms.Padding(0, 0, 0, 1);
            this.testGridView.Size = new System.Drawing.Size(833, 444);
            this.testGridView.TabIndex = 0;
            this.testGridView.Text = "radGridView1";
            //
            // resetButton
            //
            this.resetButton.Location = new System.Drawing.Point(90, 460);
            this.resetButton.Name = "resetButton";
            this.resetButton.Size = new System.Drawing.Size(130, 24);
            this.resetButton.TabIndex = 1;
            this.resetButton.Text = "Reset datasources";
            this.resetButton.Click += new System.EventHandler(this.resetButton_Click);
            //
            // TestGridForm2
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(833, 494);
            this.Controls.Add(this.resetButton);
            this.Controls.Add(this.testGridView);
            this.Name = "TestGridForm2";
            this.Padding = new System.Windows.Forms.Padding(0, 0, 0, 50);
            //
            //
            //
            this.RootElement.ApplyShapeToControl = true;
            this.Text = "Test Form";
            ((System.ComponentModel.ISupportInitialize)(this.testGridView)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.resetButton)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
            this.ResumeLayout(false);
 
        }
 
        #endregion
 
        private Telerik.WinControls.UI.RadGridView testGridView;
        private Telerik.WinControls.UI.RadButton resetButton;
 
    }
}

Thanks
Frederik

11 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 13 Oct 2010, 05:19 PM
Hi Fred, 

i think that this may be the same as your other post in that it needs the latest version as I couldnt replicate it. 

Let me know if it's still there once you've upgraded. 
Richard
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Oct 2010, 07:52 PM
Hello Fred,

Try switching these two lines:
// this
//childGridViewTemplate.DataSource = myChildList;
//testGridView.DataSource = myParentList;
 
// to this
testGridView.DataSource = myParentList;
childGridViewTemplate.DataSource = myChildList;

And let me know, i also would suggest collapsing the child grids before rebinding the parent grid.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Fred
Top achievements
Rank 1
answered on 15 Oct 2010, 11:31 AM
Hello,

I haven't tried yet with upgrading, the project leader has to give the go for that and he seems not to believe it's a problem with the version (I did mention there are reportedly *a lot* of bugfixes in that last version). I do think it a version problem but I haven't actually heard confirmation if this second problem with scrolling to the bottom can be reproduced, but I suspect it can't just like my other problem with the crash.

Emanuel>
I have tried switching those two lines, and strangely even though in the real application they *are* in parent, then child order to assign the datasources, the behaviour indeed becomes different in my test case, being it doesn't scroll to the bottom anymore when selecting a child. There is however a new problem, a random row is selected and the child view automatically expanded on that row (again *if* you selected a child first before refreshing). I have tried clearing the selection, since that seemed to be the determining factor for the problem to occur, and collapsing all rows as you suggested but that seems to have no effect.

In any case, I know I should probably just upgrade to the latest version and come back to you guys if I still have a problem then but could you tell me if you have actually been able to reproduce this scrolling to the bottom problem using my test case? I'm not sure if you did from your posts.

Anyway thanks a lot for the assistance, great first-line support.

Greetings
Frederik

ps. my version is RadControls_WinForms_2010_2_10_806_dev
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 11:52 AM
Hello again,

I have managed to reproduce your issue, (with the current release 914) I offered that solution based on a few tests, but you are right, after resetting the data source, if a child row is selected it will always select the first child row in the child template.

I'll try to find a way of avoiding this and will get back to you as soon as i have something.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Richard Slade
Top achievements
Rank 2
answered on 15 Oct 2010, 11:55 AM
Hehe, you beat me to it, Emanuel. I can also reproduce it. 
Richard
0
Fred
Top achievements
Rank 1
answered on 15 Oct 2010, 01:07 PM
Hi,

great you guys can reproduce it, so I know I'm not alone, but not so great considering this will mean a workaround or waiting for next release.

Concerning a workaround, I have already tried when resetting datasource to clear the selection and collapse all children (but no effect):
ExpandAllChildren(false);
testGridView.ClearSelection();
testGridView.DataSource = myParentList;
childGridViewTemplate.DataSource = myChildList;

where ExpandAllChildren is:
private void ExpandAllChildren(Boolean expand)
{
    foreach(GridViewDataRowInfo row in testGridView.Rows)
    {
        if(row is GridViewHierarchyRowInfo)
            row.IsExpanded = expand;
    }
}

If you *could* find a way around the problem that would be very much appreciated and thanks anyway for your attention to this problem.

Greetings
Frederik
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 01:14 PM
Hello again, I have a solution, but you won't like it, because honestly it's kinnda stupid but it works, it's about removing the child template and relations and create them again on rebind...

Something like:
private void ClearAndCreateTemplateAndRelation()
{
    if (testGridView.Templates.Count != 0)
    {
        testGridView.Templates.Clear();
        if (testGridView.Relations.Count != 0)
        {
            testGridView.Relations.Clear();
        }
    }
 
    childGridViewTemplate = new GridViewTemplate();
    childGridViewTemplate.AutoGenerateColumns = true;
 
    testGridView.MasterTemplate.ShowRowHeaderColumn = true;
    childGridViewTemplate.ShowRowHeaderColumn = false;
    childGridViewTemplate.SelectLastAddedRow = false;
    testGridView.MasterTemplate.Templates.Add(childGridViewTemplate);
 
    GridViewRelation relation = new GridViewRelation(testGridView.MasterTemplate);
    relation.ChildTemplate = childGridViewTemplate;
    childGridViewTemplate.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    relation.RelationName = "ParentChildren";
    relation.ParentColumnNames.Add("id");
    relation.ChildColumnNames.Add("parent_id");
 
    testGridView.Relations.Add(relation);
}

But maybe, if you don't have a really large number of records in the grid it will work as a TEMPORARY patch.

Please let me know how it goes.

Best Regards,
Emanuel Varga
0
Fred
Top achievements
Rank 1
answered on 15 Oct 2010, 02:05 PM
Hi Emanuel,

oh great, that works indeed if I reset that stuff before resetting the datasources. The amount of rows doesn't matter I think, GridView would have to rebuild it's internal children offset list/tree anyway when reassigning the datasources, and the operation to add a template and relation are fast in comparison. Anyway I haven't noticed a speed difference, so I'll just use your workaround for now (until next release I hope ;)

Thanks for the help and cheers
Frederik
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Oct 2010, 02:16 PM
Glad to help, if you have any other questions please let me know,

Best Regards,
Emanuel Varga
0
Accepted
Jack
Telerik team
answered on 21 Oct 2010, 08:47 AM
Hi guys,

I also confirm that the described issue appears in our latest release. I added it in our issue tracking system and it will be addressed in the upcoming release - Q3 2010.

Should you have further questions, do not hesitate to ask.
 
Sincerely yours,
Jack
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Fred
Top achievements
Rank 1
answered on 19 Nov 2010, 04:37 PM
Hi,

I can confirm this is fixed in 2010 Q3 :)

Greetings
Frederik
Tags
GridView
Asked by
Fred
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Fred
Top achievements
Rank 1
Jack
Telerik team
Share this question
or