List Databinding Performance With DisplayMembers and ValueMembers

My copy of MSDN magazine arrived last night, and I read the article Practical Tips For Boosting The Performance Of Windows Forms Apps. Good read. Anyway, I was shocked to find out that I have been databinding lists improperly ever since I have been using .Net. I frequently wrote my code like this:

//Bad Code
combobox.DataSource = datatable;
combobox.DisplayMember = “State”;
combobox.ValueMember = “Id”;

//Good Code
combobox.DisplayMember = “State”;
combobox.ValueMember = “Id”;
combobox.DataSource = datatable;

Apparenly, order matters very much. In the first example, the combobox binds using the DisplayMember, then rebinds when updated with the ValueMember. In the second example, the binding only happens once.

In our current app, we have two lists that contain thousands of items that need to be bound, so we are binding them during the startup process so the user won’t wait when requesting that data. The startup time was reduced by just under 40% by changing the order of the code for binding.