Thursday, January 22, 2009

Setting up your ComboBoxes, Fluent Style

Impossibility is not an option! - Fluent ComboBox configuration

“While refactoring an application today, I had to configure a couple of ComboBoxes programmaticaly.
To simplify this, I cam up with the following piece of code.

It implements a fluent interface to setup the ComboBox with a little less noisy code:

 ComboboxBinder.Bind(cboType)
.ViewForDataSource(_typeTable, "", "Name")
.DisplayMember("Name")
.ValueMember("TypeID")
.SelectedIndex(1);
        ComboboxBinder.Bind(cboState)
.ViewForDataSource(_stateTable)
.DisplayMember("Description")
.ValueMember("StateID")
.SelectedIndex(1);

Hopefully its useful for someone. Of course you would probably have it change it to fit your needs.”

While I’m still wrapping my head around “Fluent,” I thought this sample was cool. It has immediate benefit and helps me in any area that I always seem to be reinventing, my silly combobox setup coding.

No comments: