Results 1 to 5 of 5

Thread: convert string to a control type

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    16

    convert string to a control type

    Hi All,

    Using Win2k
    When I return a db column via a datareader to my app I'll see that rdr("ControlType") contains "Label" or "Textbox", etc. I'd like to use this string to as a datatype for a variable. I have tried...

    Dim ct As Control = CType(TypeDescriptor.GetConverter(GetType(Control)).ConvertFromString(rdrFormBuild("controltype").To String), Control)

    but that returns Nothing. I know that for a color "red" you can use the FromName method to return a valid color object so there must be something like this for other objects??? Any ideas?

    I'll also post on ASP.NET

    Thanks,
    David X

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    you may want to double check that

    rdrFormBuild("controltype") isnt returning a blank string
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    16

    convert string to a control type

    I did do...

    ?CType(TypeDescriptor.GetConverter(GetType(Control)).ConvertFromString(rdrFormBuild("controltype").T oString), Control)

    in the immediate box and it does indeed return Nothing vs "".

    Regardless of what it returns it does not return a control type. Any idea how I can get there?

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    the question was what does rdrFormBuild("controltype").ToString

    return. it may be returning a blank string and therefore may be why it doesnt work
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    16

    convert string to a control type

    Sorry. Now I understand what you wrote. I guess the conversion attempt fails thus it returns Nothing.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width