From: Nime on
I use a propertygrid with a question which one answered as Yes or No
but initial value is blank. Answered as Yes/No is a must. So how can I
convert Yes/No/{Blank} to Yes/No.

If blank chosen, default value No will be used in app. config file.

I couldn't build {Blank}/Yes/No listbox. Now I messed with class converter :
(


Simply how can I add {Blank} to listbox?



public enum YesNoEmpty
{
Empty = -1,
No = 0,
Yes = 1
}


[TypeConverter(typeof(YesNoClassConverter))]
[DisplayName("Can login")]
public YesNoEmpty peerCanLogin
{
get { return (YesNoEmpty)_peerCanLogin; }
set { _peerCanLogin = (YesNoEmpty)value == YesNoEmpty.Yes ?
YesNo.Yes : YesNo.No; }
}




class YesNoClassConverter : BooleanConverter
{
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destType)
{
try { return (YesNo)value == YesNo.Yes ? YesNo.Yes :
YesNo.No; } catch { return YesNo.No; }
}
public override object ConvertFrom(ITypeDescriptorContext
context, CultureInfo culture, object value)
{
switch ((string)value)
{
case "Yes": return YesNo.Yes; break;
default: return YesNo.No;
}

//return (string)value == "" ? YesNo.Yes : YesNo.No;
}
}