J
JaedenRuiner
Guest
Simple Setup:
class MyObject {
public string Name {get;set;}
public BindingList<ChildObject> Children {get;set;}
}
BindingList<MyOjbect> blist1;
BindingSource bs1;
BindingSource bs2;
ComboBox cb;
DataGridView dgv;
class Form1 : Form {
override OnShown() {
bs1.DataSource = blist1;
cb.DataSource = bs1;
cb.DisplayMameber = "Name";
// this does not show the actual data in the dgv.
bs2.DataSource = bs1;
bs2.DataMember = "Children"
dgv.DataSource = bs2;
}
// using this event system works
void bs1_CurrentChanged() {
dgv.DataSource = bs1.Current;
dgv.DataMember = "Children";
}
}
so, quite obviously a pseudo code here, but simply a simple nested collection of objects, (using BindingList for ease of binding). A form with a combobox, datagridview, and two bindingsources objects. If I assign the bs2 binding source to use the first bindingsource as its data source, the data grid view will show 10 rows or 4 rows, etc, but all the databound defined columns will be blank, as if there is no data. I can even trap the "row select" event for the datagrid view, and the Row.DataBoundItem is Accurate, but the data is not being visual displayed by the grid.
However, if I instead trap the "currentchanged" event of the binding source, I can assign the "Current" to the datagridview data source, assign the DataMember and suddenly i get the data displayed in the grid.
This behavior is very strange. Why is it not working as nested binding sources?
Thanks
Jaeden "Sifo Dyas" alRaec Ruiner
"Never Trust a computer. Your brain is smarter than any micro-chip."
PS - Dont mark answers on other peoples questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
Continue reading...
class MyObject {
public string Name {get;set;}
public BindingList<ChildObject> Children {get;set;}
}
BindingList<MyOjbect> blist1;
BindingSource bs1;
BindingSource bs2;
ComboBox cb;
DataGridView dgv;
class Form1 : Form {
override OnShown() {
bs1.DataSource = blist1;
cb.DataSource = bs1;
cb.DisplayMameber = "Name";
// this does not show the actual data in the dgv.
bs2.DataSource = bs1;
bs2.DataMember = "Children"
dgv.DataSource = bs2;
}
// using this event system works
void bs1_CurrentChanged() {
dgv.DataSource = bs1.Current;
dgv.DataMember = "Children";
}
}
so, quite obviously a pseudo code here, but simply a simple nested collection of objects, (using BindingList for ease of binding). A form with a combobox, datagridview, and two bindingsources objects. If I assign the bs2 binding source to use the first bindingsource as its data source, the data grid view will show 10 rows or 4 rows, etc, but all the databound defined columns will be blank, as if there is no data. I can even trap the "row select" event for the datagrid view, and the Row.DataBoundItem is Accurate, but the data is not being visual displayed by the grid.
However, if I instead trap the "currentchanged" event of the binding source, I can assign the "Current" to the datagridview data source, assign the DataMember and suddenly i get the data displayed in the grid.
This behavior is very strange. Why is it not working as nested binding sources?
Thanks
Jaeden "Sifo Dyas" alRaec Ruiner
"Never Trust a computer. Your brain is smarter than any micro-chip."
PS - Dont mark answers on other peoples questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.
Continue reading...