Home All Groups Group Topic Archive Search About

UI to enter values into a structure

Author
1 Jun 2006 10:45 PM
jim_adams
For a nested structure such as:

Dim userVariable as one

structure one
  dim a as string
  dim b() as two
end structure

structure two
  dim c as string
  dim d as string
end structure

before I do the monkey work of creating a VB.Net UI for an end user to
fill out values for userVariable, I was wondering if there's a generic
code sample that will take in a structure and provide a dynamic form to
fill out its properties.  Although the nested structure I'm working
with is more complex than this example, all data types are either
strings or integers.

Any insight is greatly appreciated.

Thanks,

Jim

Author
2 Jun 2006 6:03 AM
GhostInAK
Hullo Jimbo,
Your best bet is going to lie with the Reflection classes. 

Check out the System.Type class... something along the lines of:

Public Structure Foo
    Private sSomeString As String

    Public Property SomeString As String
        Get
            Return sSomeString
        End Get
        Set (byval tValue as String)
            sSomeString = tValue
        End Set
    End Property
End Structure


Public Sub MakeForm()
    Dim tInfo as PropertyInfo = Nothing

    For Each tInfo in GetType(Foo)
        '  Do some crap.. make the form field.. etc.
    Next

end Sub


Show quoteHide quote
> For a nested structure such as:
>
> Dim userVariable as one
>
> structure one
> dim a as string
> dim b() as two
> end structure
> structure two
> dim c as string
> dim d as string
> end structure
> before I do the monkey work of creating a VB.Net UI for an end user to
> fill out values for userVariable, I was wondering if there's a generic
> code sample that will take in a structure and provide a dynamic form
> to fill out its properties.  Although the nested structure I'm working
> with is more complex than this example, all data types are either
> strings or integers.
>
> Any insight is greatly appreciated.
>
> Thanks,
>
> Jim
>
Author
2 Jun 2006 7:42 PM
jim_adams
Thanks for your help.  This seems like a good idea for a GotDotNet
project!

-Jim


GhostInAK wrote:
Show quoteHide quote
> Hullo Jimbo,
> Your best bet is going to lie with the Reflection classes.
>
> Check out the System.Type class... something along the lines of:
>
> Public Structure Foo
>     Private sSomeString As String
>
>     Public Property SomeString As String
>         Get
>             Return sSomeString
>         End Get
>         Set (byval tValue as String)
>             sSomeString = tValue
>         End Set
>     End Property
> End Structure
>
>
> Public Sub MakeForm()
>     Dim tInfo as PropertyInfo = Nothing
>
>     For Each tInfo in GetType(Foo)
>         '  Do some crap.. make the form field.. etc.
>     Next
>
> end Sub
>
>
> > For a nested structure such as:
> >
> > Dim userVariable as one
> >
> > structure one
> > dim a as string
> > dim b() as two
> > end structure
> > structure two
> > dim c as string
> > dim d as string
> > end structure
> > before I do the monkey work of creating a VB.Net UI for an end user to
> > fill out values for userVariable, I was wondering if there's a generic
> > code sample that will take in a structure and provide a dynamic form
> > to fill out its properties.  Although the nested structure I'm working
> > with is more complex than this example, all data types are either
> > strings or integers.
> >
> > Any insight is greatly appreciated.
> >
> > Thanks,
> >
> > Jim
> >