When using GridView in Hierarchy mode with a Template and binding to BindingList for Children:
public
class
Parent
{
public
Parent()
{
children =
new
BindingList<Child2>();
}
public
int
Id {
get
;
set
; }
public
string
Prop1 {
get
;
set
; }
public
BindingList<Child2> children {
get
;
set
; }
}
public
class
Child2 : INotifyPropertyChanged
{
public
int
Id {
get
;
set
; }
public
string
Prop1 {
get
;
set
; }
private
int
_Prop2;
public
int
Prop2
{
get
{
return
this
._Prop2; }
set
{
if
(
this
._Prop2 != value)
{
this
._Prop2 = value;
if
(PropertyChanged !=
null
)
PropertyChanged(
this
,
new
PropertyChangedEventArgs(
"Prop2"
));
}
}
}
public
string
Prop3 {
get
;
set
; }
public
event
PropertyChangedEventHandler PropertyChanged;
}
If there is grouped columns in child template, changing properties is not reflected:
public
partial
class
Form1 : Form
{
BindingList<Parent> data;
public
Form1()
{
InitializeComponent();
InitGrid();
data =
new
BindingList<Parent>();
for
(
int
i = 0; i < 3; i++)
{
Parent parent =
new
Parent() { Id = i, Prop1 =
"testProp"
+ i };
for
(
int
j = 0; j < 4; j++)
{
Child2 child =
new
Child2() { Id = i * j, Prop1 =
"testProp"
+ i, Prop2 = j % 2, Prop3 =
"another"
};
parent.children.Add(child);
}
data.Add(parent);
}
this
.radGridView1.DataSource = data;
this
.radGridView1.CellDoubleClick += radGridView1_CellDoubleClick;
}
void
radGridView1_CellDoubleClick(
object
sender, GridViewCellEventArgs e)
{
Child2 child = e.Row.DataBoundItem
as
Child2;
MessageBox.Show(child.Prop2.ToString());
}
private
void
InitGrid()
{
this
.radGridView1.Columns.Add(CreateColumn(
"Id"
));
this
.radGridView1.Columns.Add(CreateColumn(
"Prop1"
));
GridViewTemplate template =
new
GridViewTemplate();
template.AllowAddNewRow =
false
;
template.AllowDeleteRow =
false
;
template.AllowEditRow =
false
;
template.AutoGenerateColumns =
false
;
template.Columns.Add(CreateColumn(
"Id"
));
template.Columns.Add(CreateColumn(
"Prop1"
));
template.Columns.Add(CreateColumn(
"Prop2"
));
template.Columns.Add(CreateColumn(
"Prop3"
));
GridViewRelation r =
new
GridViewRelation(
this
.radGridView1.MasterTemplate, template);
r.ChildColumnNames.Add(
"children"
);
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
template.EnableFiltering =
false
;
template.EnableGrouping =
true
;
template.ShowColumnHeaders =
true
;
template.ShowRowHeaderColumn =
false
;
this
.radGridView1.EnableGrouping =
false
;
this
.radGridView1.EnableCustomGrouping =
false
;
GroupDescriptor gd =
new
GroupDescriptor();
gd.GroupNames.Add(
"Prop2"
, ListSortDirection.Ascending);
gd.GroupNames.Add(
"Prop3"
, ListSortDirection.Ascending);
template.GroupDescriptors.Add(gd);
this
.radGridView1.Templates.Add(template);
this
.radGridView1.Relations.Add(r);
this
.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
GridViewTextBoxColumn CreateColumn(
string
Field)
{
GridViewTextBoxColumn col =
new
GridViewTextBoxColumn();
col.Name = Field;
col.FieldName = Field;
col.HeaderText = Field;
return
col;
}
private
void
button1_Click(
object
sender, EventArgs e)
{
this
.data.First().children.First().Prop2 = 1;
}
}
When I Click Button1 nothing happens
Is this a bug or am I doing something wrong?