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:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...