Code Snippet
namespace Sample18
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void Form3_Load(object sender, EventArgs e)
{
this.propertyGrid1.SelectedObject = new a();
}
}
class myTypeConverter : TypeConverter
{
private bool isNull = true;
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value.ToString() == "")
{
isNull = true;
return 0;
}
else
{
isNull = false;
return Convert.ToInt32(value);
}
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (Convert.ToInt32(value) == 0)
{
return isNull "" : "0";
}
return value.ToString();
}
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(int))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
}
class a
{
private int m_int;
private int m_int2;
private string m_string;
[TypeConverter(typeof(myTypeConverter))]
public int M_INT
{
get { return m_int; }
set { m_int = value; }
}
[TypeConverter(typeof(myTypeConverter))]
public int M_INT2
{
get { return m_int2; }
set { m_int2 = value; }
}
public string M_String
{
get { return m_string; }
set { m_string = value; }
}
}
}