ComboBox Databinding and NullsComboBox Databinding and Nulls
Old forum URL: forums.lhotka.net/forums/t/6641.aspx
xAvailx posted on Thursday, March 19, 2009
CSLA 3.6 / WinForms / Databinding (sigh)
I am sure this has been discussed a thousand times but I can't find any relevant posts.
I have a combobox that should allow an "empty/null" selection. I have a class that has a nullable property. My problem is I can't figure out how to have the combobox with an empty value and databound. in asp.net this is pretty easy...but can't find how to do it in WinForms.
Any help is appreciated. thx.
sergeyb replied on Thursday, March 19, 2009
I usually just add a fake blank row (with appropriate ID of zero) into the underlying data source (ROLB or NVL). This way you do not need to mess with nullable values that usually is a pain.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation
-----Original Message-----
From: xAvailx [mailto:cslanet@lhotka.net]
Sent: Thursday, March 19, 2009 4:23 PM
To: Sergey Barskiy
Subject: [CSLA .NET] ComboBox Databinding and Nulls
CSLA 3.6 / WinForms / Databinding (sigh)
I am sure this has been discussed a thousand times but I can't find any relevant posts.
I have a combobox that should allow an "empty/null" selection. I have a class that has a nullable property. My problem is I can't figure out how to have the combobox with an empty value and databound. in asp.net this is pretty easy...but can't find how to do it in WinForms.
Any help is appreciated. thx.
tetranz replied on Thursday, March 19, 2009
Sometimes it's nice to keep the data clean and only add the fake item for the UI so I still use my so called "HeadedBindingList" to do what Sergey is suggesting. See my post on the second page of this old thread http://forums.lhotka.net/forums/thread/4676.aspx
I too give the fake item an id of 0 or Guid.Empty to avoid messing with nulls.
Copyright (c) Marimer LLC