hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Using custom types in PropertyGrid with F#

Last post 07-25-2008, 7:50 by kyagrd. 0 replies.
Sort Posts: Previous Next
  •  07-25-2008, 7:50 6444

    Using custom types in PropertyGrid with F#

    #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
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems