Hello Roman,
Thank you for writing.
I have prepared a sample code snippet demonstrating that when updating a property in the
DataBoundItem doesn't collapse the expanded rows:
BindingList<Student> collectionOfStudents =
new
BindingList<Student>();
BindingList<School> collectionOfSchools =
new
BindingList<School>();
public
Form1()
{
InitializeComponent();
collectionOfStudents.Add(
new
Student(1,
"Peter"
,
"D-"
,2));
collectionOfStudents.Add(
new
Student(2,
"Antony"
,
"B+"
,1));
collectionOfStudents.Add(
new
Student(3,
"David"
,
"A-"
,1));
collectionOfStudents.Add(
new
Student(4,
"John"
,
"D-"
,2));
collectionOfSchools.Add(
new
School(
"Schrool 1"
,1));
collectionOfSchools.Add(
new
School(
"Schrool 2"
,2));
radGridView1.DataSource = collectionOfSchools;
radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
GridViewTemplate template =
new
GridViewTemplate();
template.DataSource = collectionOfStudents;
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
radGridView1.MasterTemplate.Templates.Add(template);
GridViewRelation relation =
new
GridViewRelation(radGridView1.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName =
"SchoolsStudents"
;
relation.ParentColumnNames.Add(
"Id"
);
relation.ChildColumnNames.Add(
"SchoolId"
);
radGridView1.Relations.Add(relation);
}
public
class
School: System.ComponentModel.INotifyPropertyChanged
{
string
_name;
int
_id;
public
School(
string
name,
int
id)
{
this
._name = name;
this
._id = id;
}
public
string
Name
{
get
{
return
this
._name;
}
set
{
this
._name = value;
OnPropertyChanged(
"Name"
);
}
}
public
int
Id
{
get
{
return
this
._id;
}
set
{
this
._id = value;
OnPropertyChanged(
"Id"
);
}
}
public
event
PropertyChangedEventHandler PropertyChanged;
protected
virtual
void
OnPropertyChanged(
string
propertyName)
{
if
(PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
}
public
class
Student : System.ComponentModel.INotifyPropertyChanged
{
int
m_id;
string
m_name;
string
m_grade;
int
school_id;
public
event
PropertyChangedEventHandler PropertyChanged;
public
Student(
int
m_id,
string
m_name,
string
m_grade,
int
s_id)
{
this
.m_id = m_id;
this
.m_name = m_name;
this
.m_grade = m_grade;
this
.school_id = s_id;
}
public
int
Id
{
get
{
return
m_id;
}
set
{
if
(
this
.m_id != value)
{
this
.m_id = value;
OnPropertyChanged(
"Id"
);
}
}
}
public
string
Name
{
get
{
return
m_name;
}
set
{
if
(
this
.m_name != value)
{
this
.m_name = value;
OnPropertyChanged(
"Name"
);
}
}
}
public
string
Grade
{
get
{
return
m_grade;
}
set
{
if
(
this
.m_grade != value)
{
this
.m_grade = value;
OnPropertyChanged(
"Grade"
);
}
}
}
public
int
SchoolId
{
get
{
return
this
.school_id;
}
set
{
this
.school_id = value;
OnPropertyChanged(
"SchoolId"
);
}
}
protected
virtual
void
OnPropertyChanged(
string
propertyName)
{
if
(PropertyChanged !=
null
)
{
PropertyChanged(
this
,
new
PropertyChangedEventArgs(propertyName));
}
}
}
private
void
radButton1_Click(
object
sender, EventArgs e)
{
collectionOfStudents[1].Name =
"Name"
+ DateTime.Now.ToLongTimeString();
}
The following help article demonstrates how to reflect custom object changes in
RadGridView:
http://docs.telerik.com/devtools/winforms/gridview/populating-with-data/reflecting-custom-object-changes-in-rgv
However, if you reset the
DataSource property of
RadGridView, before setting the
property keep in an appropriate data structure which
are the expanded rows and restore them after that.
I hope this information helps. Should you have further questions I would be glad to help.
Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this
blog post and share your thoughts.