views:

527

answers:

2

Is there a quick way to add a blank value to a drop down list for a winforms application? Some of my dropdowns are bound to lists of objects and some are bound to datarows from a datatable. Since I am setting the datasource property, I can't just add one through code. Is there any quick way of getting a blank value added or will I have to do it manually for each drop down?

+1  A: 

You could add a DataRow with empty values to your datatable programatically,

nos
That's what I figured. But I wasn't sure if there was a quick four-liner that would just add a blank object to the drop down list.
Josh
A: 

Here's one I've used to do a blank entry before enum values. Obviously this won't work for more complex binding scenarios.

combo1.DataSource = (new object[] { null }
                        .Concat(Enum.GetValues(typeof(myEnumType)).Cast<object>()))
                            .ToList();
frou