How to Select Null/None in a ComboBox/ListBox/ListView

Phil On .NET

When using a Selector control like ComboBox, ListBox, or ListView to present a non-required/optional field, you might want a special item like “(None)” to appear in the list, representing null/DBNull. This is a fairly common scenario, particularly with nullable foreign keys, but how to accommodate this requirement in the view may not be straightforward when you’re data-binding the ItemsSource, which is typically the case.

Although you could add a special object representing null (which we’ll call the “None” item) to the source collection itself, for practical and philosophical reasons you probably don’t want to modify the collection just to accommodate a particular presentation of it. Of course, if your collection consists of individual data wrappers or view models, adding the None object to the collection may not be an issue. Regardless, we’ll proceed with the assumption that you don’t want to modify the source collection.

A nice way to include…

View original post 181 more words

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s