#light
open System.Windows.Forms
open System.ComponentModel
[<TypeConverter(typeof<PersonConverter>)>]
type Person(pv : int) =
let mutable value = pv
member x.v
with get () = value
and set (x) = value <- x
and PersonConverter() =
inherit ExpandableObjectConverter() as base
override x.CanConvertFrom(ctxt, ty) = ty = typeof<string> || base.CanConvertFrom(ctxt,ty)
override x.ConvertFrom(ctxt, info, o) = match o with
| :? string -> (new Person(int(o :?> string)) :> obj)
| _ -> base.ConvertFrom(ctxt, info, o)
override x.CanConvertTo(ctxt, ty) = ty = typeof<string> || base.CanConvertTo(ctxt,ty)
override x.ConvertTo(ctxt, info, o, ty) = match o with
| :? Person when ty = typeof<string> -> (o :?> Person).v.ToString() :> obj
| _ -> base.ConvertTo(ctxt,info,o,ty)
Application.EnableVisualStyles()
let form2 = new Form(Text = "Hello Properties")
let pg = new PropertyGrid(Dock = DockStyle.Fill, CommandsVisibleIfAvailable = true)
pg.TabIndex = 1
pg.Text = "Property Grid"
form2.Controls.Add(pg)
pg.SelectedObject <- [|new Person(18); new Person(25)|]
form2.Show()
// form2.Close()
// References
// http://msdn.microsoft.com/en-us/library/aa302326.aspx
// http://msdn.microsoft.com/en-us/library/aa302334.aspx
// http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx