Groups | Blog | Home
all groups > dotnet windows forms > may 2006 >

dotnet windows forms : Adding a blank row to top of ComboBox


Jay Douglas
5/13/2006 10:24:56 AM
I'm binding an IList to a WinForm combox box DataSource
(ComboxBox.DataSource = myList) and am unable to add a blank row to the top
of the combox. I want users to have the option to not select a value.

I've tried the following things:

myBox.Items.Insert(0, null);

((IList)myBox.DataSource).Insert(0, null)

Both of these attempts have been greeted by exceptions. Please let me know
if you know of any way to solve my problem.

Thanks,
Jay

Robbe Morris [C# MVP]
5/13/2006 2:53:42 PM
Add the item to your IList. If you set its ID to something
you recognize as not selected or perhaps have a property
on the class to designate the same, you are in business.

--
Robbe Morris - 2004-2006 Microsoft MVP C#
Earn money answering .NET questions
http://www.eggheadcafe.com/forums/merit.asp





[quoted text, click to view]

Gaurav Vaish (EduJini.IN)
5/14/2006 12:00:00 AM
Inserting null does not work.
You need add a dummy instance.

You can directly do myBox.Items.Insert(0, myDummyInstance).
Don't forget to override the "ToString" method... coz that's what is visible
in the box.

--

Cheers,
Gaurav Vaish
http://www.mastergaurav.org
http://www.edujini.in
-------------------


[quoted text, click to view]

AddThis Social Bookmark Button