databinding

I'm reading someone elses code, and I came across the following segment, renamed for clarity

        ComboBoxA.DataSource = myDataSet;
        ComboBoxA.DisplayMember = "t.blah";
        ComboBoxA.DataBindings.Add("Text", myDataSet, "t.blah");

don't the last two lines of this accomplish the same thing, and if not, what is the purpose of the line:
         ComboBoxA.DataBindings.Add("Text", myDataSet, "t.blah")
ARACK04Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravi SinghSenior Software EngineerCommented:
Hi,

Two types of binding techniques are being used there, the first two lines are known as complex binding. If you had them alone then the combobox's  would contain all the values in the "blah" column... although when using complex binding the property ValueMember is usually set too (not necessary).

The last line represents simple binding where the Text property of the combobox is binded to the "blah" column in table "t" which is in the dataset "myDataSet". If you had this line alone then the combobox would only show one value... the value which the current record holds... you can go to the next value by obtaining a reference to the BindingManagerBase and incremementing the position property:

ComboBoxA.DataBindings["Text"].BindingManagerBase.Position++;

I think in this case the person who wrote the code only intentionally wanted the first two lines...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ready1Commented:
normally you do not need the

ComboBoxA.DataBindings.Add("Text", myDataSet, "t.blah");

maybe you copied the code from a cautious programmer :).

this normally is enough for WinForms
        ComboBoxA.DataSource = myDataSet;
        ComboBoxA.DisplayMember = "t.blah";
but ASP.Net requires
        ComboBoxA.DataBind();

Regards,
Ready1

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.