0

trying to add a dropdown into a property grid

Im using VS2010 VB.net with reflection

For my full solution - Download it here

https://www.nyvault.com/files/reflection/xml_propgrid_reflect_sk.zip

Password is 1

The point of this project is to populate a propertyGrid I dont want to create a custom grid, i just want to populate the already made out of the box generic microsoft thing.

basically, I get the class to be created with reflection. using data from XML Some of the fields use a custom type (this will be used for the dropdown)

This is what happens when I run the solution: So i make the class, and it looks fine It creates everything and sets it up. then when I make an instance of this class in my MAIN() in calls a default constructor [new()] for the type(which is hardcoded dropdown items) instead of the custom constructor I wanted [new(byval test as integer)]

basically here are the class constructors for the custom type (located in customlist.vb)

 Public Sub New()     
        ' Gather all the localized strings currently loaded
        ' Gather all the strintTables from the current project.    
        For i As Integer = 0 To 4
            myStringCollection.Add(New MyString(100 + i, "Test " & i))
        Next
    End Sub


   Public Sub New(ByVal val As Integer)      
        For i As Integer = 0 To val
            myStringCollection.Add(New MyString(100 + i, "Testy " & i))
        Next
    End Sub

it calls the Public Sub New() but i want to call the Public Sub New(ByVal val As Integer)

please help, this has been making me rip my hair out for two months.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Ess Kay
  • 598
  • 4
  • 20
  • What happens if you don't provide a parameterless constructor or set its access level to private? – djv May 06 '13 at 16:30
  • then it gives an error, no constructor found – Ess Kay May 06 '13 at 19:23
  • You can't use another constructor for a TypeConverter. When working with the property grid, converters, etc. you're supposed to use the ITypeDescriptorContext to get some context information. BTW, are you aware the property grid supports ICustomTypeDescriptor (in other words, you don't have to build a complete type using Reflection emit), you can just create a type that derives from it and returns the properties dynamically. – Simon Mourier May 07 '13 at 08:14
  • @Simon Please run the project. The reflection is there to create everything else in a property grid. some properties happen to have dropdowns. Since dropdown isnt really an int, string or any other thing, i have to create a new type to facilitate the results in it. From what you are saying, it seems that you suggest I hardcode it. The text and values actually come from any xml file fed into it, on the fly it converts the xml into a class using reflection and binds the propertygrid to the new class. If you can give me an example it would be much appreciated – Ess Kay May 07 '13 at 16:01
  • I ran your project. You can provide to the PG an ICustomTypeProvider object that overrides GetProperties(...) (and some other methods to work properly) to create an object dynamically like you want. What you've done works too, it's just seems more complicated unless you really need a Type. For the question about the dropdown, I just don't understand your problem or what you're trying to do:-) – Simon Mourier May 07 '13 at 17:04
  • Currently the dropdown is a new Type object called customlist. It gets its info from hardcoded loop 0-5 in the NEW() constructor. I want to pass the values to it from somewhere else and call the new(int) constructor instead. The parameter needs to be passed, and then the loop will vary of how many options are there. Ultimately, we will pass objects into the constructor, but at the moment, i just need it to work with something simple, like a number – Ess Kay May 07 '13 at 18:33
  • i mean, if you know a better way to dynamically bind xml stuffs to a property grid, im all ears. I just see this as the only way that I can do it. ----all examples ive seen online which do what i need create a custom property grid. I want to bypass that and just make a dll which gets an xml, and returns an object. property grid is set to object. – Ess Kay May 07 '13 at 18:38
  • what I have used in the past to do what you describe (display things in the property grid from a dynamic source) is the PropertyBag described here: http://www.codeproject.com/Articles/3397/Bending-the-NET-PropertyGrid-to-Your-Will. – Ben May 08 '13 at 17:13
  • i fail to see any dropdowns in the property bag project – Ess Kay May 28 '13 at 15:06

0 Answers0