Groups | Blog | Home
all groups > dotnet windows forms databinding > may 2005 >

dotnet windows forms databinding : Combobox databinding context not working


Rasmus.Christensen
5/11/2005 11:59:08 PM
Hey

I have a form with som textboxes that uses databinding like this:
The "mysource" contains objects with Number, FirstName and a Type

box1Txt.DataBindings.Add("Text", mysource, "Number");
box2Txt.DataBindings.Add("Text", mysource, "FirstName");

This works find and I'm able to navigate using the
bindingcontext/Bindingmanagerbase.Position.

Next I want to bind the Type property to a combobox which contains "Types"
from another source:

Types = new Types();
myCombobox.BindingContext = new BindingContext();
myCombobox.Sorted = false;
myCombobox.DataSource = empType;
myCombobox.DataBindings.Add("SelectedItem", mysource, "Type");
myCombobox.DisplayMember = "Name";

Well when I now navigate with the bindingcontext in the mysource nothing
happens in the combobox, why not. I want the combobox to match the Type from
the object in mysource.




Beth Massi [Architect MVP]
5/12/2005 4:48:27 PM
Try this:

myCombobox.DataSource = empType;
myCombobox.DisplayMember = "Name";
myCombobox.ValueMember = "Type";
myCombobox.DataBindings.Add("SelectedValue", mysource, "Type");

"Rasmus.Christensen" <Rasmus.Christensen@discussions.microsoft.com> wrote in
message news:5D2D48D4-8BD8-4F09-B1A7-BF50F60E55C0@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button