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
TestGridForm2.Designer.cs
Thanks
Frederik
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