using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Dummy_PropertyGrid
{
class MyConverter : TypeConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
List<string> list = (context.Instance as Form1.myProp).MyList;
StandardValuesCollection cols = new
StandardValuesCollection(list);
return cols;
}
}
public partial class Form1 : Form
{
public class myProp
{
string myStr;
[TypeConverter(typeof(MyConverter))]
public string MyItem
{
get { return myStr; }
set { myStr = value; }
}
List<string> list;
[Browsable(false)]
public List<string> MyList
{
get
{
if (list == null)
{
list = new List<string>();
list.Add("aaa");
list.Add("bbb");
list.Add("ccc");
}
return list;
}
}
}
public Form1()
{
InitializeComponent();
myProp obj = new myProp();
obj.MyList.Add("ddd");
obj.MyList.Add("eee");
this.propertyGrid1.SelectedObject = obj;
}
}
}
|