or
I am creating a hierarchy grid using object relational data. I am adding a GridViewRelation manually to link the two classes together. The data loads correctly at first, but then selecting a child row will cause all child rows in that position to be duplicated and selected.
After initial data load, everything looks great.
(See dataload.png)
Select Child 2_1 and all first position children are selected.
(see select1.png)
Select Child 3_2 and now all second position children are selected, and the first position children are now duplicates of each other and read Child 4_1.
(see select2.png)
Here is the code:
namespace TestGrid
{
public partial class Form1 : Form
{
private BindingList<
MasterObject
> data;
public Form1()
{
InitializeComponent();
SetupGrid();
}
private void SetupGrid()
{
LoadMasterTemplate(grid.MasterTemplate);
GridViewTemplate childTemplate = new GridViewTemplate();
LoadChildTemplate(childTemplate);
grid.MasterTemplate.Templates.Add(childTemplate);
GridViewRelation relation = new GridViewRelation(grid.MasterTemplate, childTemplate);
relation.RelationName = "Children";
relation.ChildColumnNames.Add("Children");
grid.Relations.Add(relation);
}
private void LoadMasterTemplate(GridViewTemplate template)
{
template.Columns.Clear();
template.EnableFiltering = false;
template.AllowAddNewRow = false;
template.ShowChildViewCaptions = false;
template.AutoGenerateColumns = false;
template.EnableGrouping = false;
GridViewTextBoxColumn colNode = new GridViewTextBoxColumn("NodeDesc");
colNode.HeaderText = "Node";
colNode.Name = "Node";
colNode.ReadOnly = true;
template.Columns.Add(colNode);
GridViewTextBoxColumn colName = new GridViewTextBoxColumn("Name");
colName.HeaderText = "Name";
colName.Name = "Name";
template.Columns.Add(colName);
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
private void LoadChildTemplate(GridViewTemplate template)
{
template.Columns.Clear();
template.EnableFiltering = false;
template.EnableGrouping = false;
template.AllowAddNewRow = false;
template.AutoGenerateColumns = false;
GridViewTextBoxColumn colNode = new GridViewTextBoxColumn("NodeDesc");
colNode.HeaderText = "Node";
colNode.Name = "Node";
colNode.ReadOnly = true;
template.Columns.Add(colNode);
GridViewTextBoxColumn colIP = new GridViewTextBoxColumn("Name");
colIP.Name = "Name";
colIP.HeaderText = "Name";
template.Columns.Add(colIP);
template.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
}
private void LoadData()
{
data = new BindingList<
MasterObject
>();
for (int i = 1; i <
5
; i++)
{
MasterObject
m
=
new
MasterObject();
m.Name
=
"Master "
+ i;
for (int
x
=
1
; x < i; x++)
{
ChildObject
c
=
new
ChildObject();
c.Name
=
"Child "
+ i + "_" + x;
m.Children.Add(c);
}
data.Add(m);
}
grid.DataSource
=
data
;
}
private void button1_Click(object sender, EventArgs e)
{
// Load Data In Grid
LoadData();
}
private void button2_Click(object sender, EventArgs e)
{
// Add Child to 1
MasterObject
m
=
data
[0];
ChildObject
c
=
new
ChildObject();
c.Name
=
"Child "
+ "1_" + (m.Children.Count + 1);
m.Children.Add(c);
}
private void button3_Click(object sender, EventArgs e)
{
// Add Child to 2
MasterObject
m
=
data
[1];
ChildObject
c
=
new
ChildObject();
c.Name
=
"Child "
+ "2_" + (m.Children.Count + 1);
m.Children.Add(c);
}
}
public class MasterObject
{
private string name;
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name
=
value
;
}
}
}
public string NodeDesc
{
get
{
return "MasterObject";
}
}
private BindingList<ChildObject> children;
public BindingList<
ChildObject
> Children
{
get
{
return children;
}
set
{
children = value;
}
}
public MasterObject()
{
children = new BindingList<
ChildObject
>();
}
}
public class ChildObject
{
private string name;
public string Name
{
get
{
return name;
}
set
{
if (name != value)
{
name = value;
}
}
}
public string NodeDesc
{
get
{
return "ChildObject";
}
}
public ChildObject() { }
}
}
<
script
type
=
"text/javascript"
>
var ord = window.ord || Math.floor(Math.random() * 1e16);
document.write('<
script
type
=
"text/javascript"
src
=
"http://ad.doubleclick.net/xxxyyyzzz/adtarget;area=default;section=default;pos=fullbanner2;sz=728x90;ord=' + ord + '?"
><\/script>');
</
script
>
protected
override
void
OnLoad(EventArgs e)
{
base
.OnLoad(e);
NorthwindDataSet nwindDataSet =
new
NorthwindDataSet();
CustomersTableAdapter customersTableAdapter =
new
CustomersTableAdapter();
customersTableAdapter.Fill(nwindDataSet.Customers);
this
.radMultiColumnComboBox1.DataSource = nwindDataSet.Customers;
//New My Code
for
(
int
i = 0 ; i <
this
.radMultiColumnComboBox1.EditorControl.Columns.Count ; i++)
{
var item =
this
.radMultiColumnComboBox1.EditorControl.Columns[i];
string
tmp= item.FieldName;
FilterDescriptor descriptor =
new
FilterDescriptor(tmp ,FilterOperator.Contains ,
null
);
this
.radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(descriptor);
this
.radMultiColumnComboBox1.EditorControl.FilterDescriptors.LogicalOperator = FilterLogicalOperator.Or;
}
//Old code
//FilterDescriptor descriptor = new FilterDescriptor(this.radMultiColumnComboBox1.DisplayMember ,FilterOperator.StartsWith ,string.Empty);
//this.radMultiColumnComboBox1.EditorControl.FilterDescriptors.Add(descriptor);
this
.radMultiColumnComboBox1.DropDownStyle = RadDropDownStyle.DropDown;
// Filtering END
}