Click here to Skip to main content
15,913,215 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I have a combobox with a bindingsource as a datasource. Inside the bindingsource, there is a collection of objects (Material object).
My main binding source which is bound to the combobox's selectedvalue property contains a quoteline object. One of the properties of quoteline, is an embedded Material object.
I would therefore want a combobox displaying a list of Material objects and when the user selects a Material from the combobox, the Material property of the Quoteline is updated with the selected object. Everthing works fine, except the initial selected item of the combobox. It just parks on the 1st object in the list. Here is my code. Please help.
C#
Material material;
Material material2;

public Form1()
        {

 
            InitializeComponent();
            prematerial = new Material();
            prematerial.MaterialId = 0;
            prematerial.MaterialDesc = "Pine";
            bindingSource1.Add(prematerial);
            material = new Material();
            material.MaterialId = 1;
            material.MaterialDesc = "Kiaat";
            bindingSource1.Add(material);
            material2 = new Material { MaterialId = 2, MaterialDesc =  
            Den;};
            bindingSource1.Add(material2);
            comboBox1.DataSource = bindingSource1;
            comboBox1.DisplayMember = "MaterialDesc";

            quoteline = new QuoteLine { Material = material2 };
            bsMaster.Add(quoteline);

            comboBox1.DataBindings.Add(new Binding("SelectedValue", bsMaster, "Material", true));
        }
Posted
Updated 1-Dec-10 2:06am
v2
Comments
Tarun.K.S 1-Dec-10 8:07am    
Use <pre lang="cs"> </pre> tags to enlcose your code. "vb" for visual basic, "xml" for xml and xaml.
Abdul Quader Mamun 1-Dec-10 9:38am    
Without Data Source how can hep you.

1 solution

Hmm, when I understand you then your problem is just how to select an specific item after binding?

MIDL
comboBox1.SelectedIndex = 3;


@ - Abdul Quader Mamun -
Its possible to help without data source - create your own - took me 30 secs. I think to demonstrate the problem you just need a databound combobox. :rose:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900