Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 287781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:45:24+00:00 2026-05-12T05:45:24+00:00

I have an App where I’d like to be able to edit any type

  • 0

I have an App where I’d like to be able to edit any type (font, colour, point etc.) at run time and use any of the .Net default type editors. (e.g., font/ colour picker).

Rather than re-invent the wheel, I decided to use the property grid control.

If I pass an object of, say font, to the grid, it lists all the fields separately, with no option to open the font picker.

Therefore, I created this generic wrapper class:

Private Class Wrapper(Of T)
    Private _Value As T
    Public Property Value() As T
        Get
            Return Me._Value
        End Get
        Set(ByVal value As T)
            Me._Value = value
        End Set
    End Property

    Public Sub New(ByVal Value As T)
        Me._Value = Value
    End Sub
End Class

Instead of passing a font object to the grid, I pass an instance of the wrapper. The property grid then behaves as I would like.

This works, but the problem is, the object could be of any type and I can’t code something like –

Dim MyWrapper = New Wrapper(of T)(myObject).

Basically, the information I have is the type’s assembly qualified name and a string representation of the object. I then use a type converter to create the object :

Dim ID As String = "System.Drawing.Font, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Dim PropertyValue As String = "Arial, 12px, style=Bold, Strikeout"
Dim T As Type = System.Type.GetType(ID)
Dim tc As TypeConverter = TypeDescriptor.GetConverter(T)
Dim o As Object = tc.ConvertFromString(PropertyValue)

If I pass the object to the property grid, it works but it doesn’t work if I pass an instance of the wrapper.

I’ve solved the problem by using reflection.Emit to create a non generic wrapper of the required type on the fly, but I suspect this is over kill.

Any ideas?

ETA:

I had a problem with what do to if I was using the Grid to edit a property, say a Font, that was not already defined.

If i define:

Dim f as Font = Nothing

, and pass that to the wrapper, the property grid displays as expected with (none) and a button with … to select the font.

My problem was how to do the equivalent of Dim myObject As ‘Type’ = Nothing, at run-time.

I couldn’t find a way to do this, but luckily with the wrapper and my type, it wasn’t a problem.
I changed Pradeep’s code (look at the answers) to :

Dim genericType As Type = GetType(Wrapper(Of ))
Dim specificType As Type = genericType.MakeGenericType(T)
Dim ci As ConstructorInfo = specificType.GetConstructor(New Type() {T})
Dim wrappedObject As Object = ci.Invoke(New Object() {Nothing})
Me.PropertyGrid1.SelectedObject = wrappedObject

Problem solved!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:45:24+00:00Added an answer on May 12, 2026 at 5:45 am

    I think this should work. I’ve tested it in C# and used a converter to get code in VB.net

    This is the code in C#

    Type generic = typeof(Wrapper<>);
    Type specific = generic.MakeGenericType(o.GetType());
    ConstructorInfo ci = specific.GetConstructor(new Type[] { o.GetType() });
    object o1 = ci.Invoke(new object[] { o });
    propertyGrid1.SelectedObject = o1;
    

    VB.NET

    Dim generic As Type =  Type.GetType(Wrapper<>) 
    Dim specific As Type =  generic.MakeGenericType(o.GetType()) 
    Dim ci As ConstructorInfo =  specific.GetConstructor(New Type() {o.GetType() })
    Dim o1 As Object =  ci.Invoke(New Object(){  o })
    propertyGrid1.SelectedObject = o1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app which could benefit from the user being able to choose
I have an app built in CI and I would like that sessions don't
We have an app with an extensive admin section. We got a little trigger
I have an app that needs to open a new window (in the same
I have an app with a large ListView which is terribly slow so I'm
I have an app using PHP and the PayPal API. The basic way it
I have an app written in C# that lies on a network share. When
I have an app where I create many uiviews and add them to the
I have an app that executes commands on a Linux server via SSH just
I have a app that I'm deploying to a development server using Capistrano. I'd

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.