T
Trecius
Hello, Newsgroupians:
I've another question regarding databinding. I have a TabControl with two
TabPages. Also -- for simplicity -- I have a ListBox and a TextBox in EACH
page.
I also have a List<Person> that I am using to populate the pages.
When the form loads, I populate each page...
this.Page1.BindingContext = new BindingContext();
this.ListBox1.DataSource = lstPersons;
this.TextBox1.DataBindings.Add("Text", lstPersons, "Name");
this.Page2.BindingContext = new BindingContext();
this.ListBox2.DataSource = lstPersons;
this.TextBox2.DataBindings.Add("Text", lstPersons, "Name");
You can note in the code that I gave each TabPage its own BindingContext, so
they don't share a common index; that is, if the selected item in one ListBox
changes, it won't reflect on the other page. Well, I run this code, and only
the FIRST PAGE changes with respect to the currently selected item in the
ListBox. The second page populates ListBox2, but when I select an item, it
does not reflect my selection in TextBox2.
However, if I do allow both pages to share the same BindingContext, when I
select an item in either ListBox, the textboxes change, but, again, if I
change the selected item on one page, it is reflected on the other page.
Any ideas what I should do? Thank you in advance.
Trecius
I've another question regarding databinding. I have a TabControl with two
TabPages. Also -- for simplicity -- I have a ListBox and a TextBox in EACH
page.
I also have a List<Person> that I am using to populate the pages.
When the form loads, I populate each page...
this.Page1.BindingContext = new BindingContext();
this.ListBox1.DataSource = lstPersons;
this.TextBox1.DataBindings.Add("Text", lstPersons, "Name");
this.Page2.BindingContext = new BindingContext();
this.ListBox2.DataSource = lstPersons;
this.TextBox2.DataBindings.Add("Text", lstPersons, "Name");
You can note in the code that I gave each TabPage its own BindingContext, so
they don't share a common index; that is, if the selected item in one ListBox
changes, it won't reflect on the other page. Well, I run this code, and only
the FIRST PAGE changes with respect to the currently selected item in the
ListBox. The second page populates ListBox2, but when I select an item, it
does not reflect my selection in TextBox2.
However, if I do allow both pages to share the same BindingContext, when I
select an item in either ListBox, the textboxes change, but, again, if I
change the selected item on one page, it is reflected on the other page.
Any ideas what I should do? Thank you in advance.
Trecius