Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Cast string to button

  • 13-06-2006 9:18am
    #1
    Registered Users, Registered Users 2 Posts: 1,466 ✭✭✭


    Im trying to make some code that can reference x amount of buttons and then switch visible to false

    For x = 1 To 10

    btnSelected = CType("btnButton" & x.ToString, Button)

    btnSelected.Visible = False

    Next

    Provides the error :

    Value of type 'String' cannot be converted to 'System.Windows.Forms.Button'.

    Any ideas, about converting string to object types such as buttons ?


Comments

  • Registered Users, Registered Users 2 Posts: 919 ✭✭✭timeout


    What language are u using? Looks like Visual Basic but can't be sure!

    [edit] actually it is I see that now.
    Do you have the buttons created?
    Could you not make a button array list?


  • Registered Users, Registered Users 2 Posts: 919 ✭✭✭timeout




  • Registered Users, Registered Users 2 Posts: 1,466 ✭✭✭Smoggy


    Thanks timeout , I looked at the problem a different way and came up with a solution using :

    for each ctrl in me.controls
    if crtl.name = myname then

    etc

    Thanks for looking


  • Registered Users, Registered Users 2 Posts: 683 ✭✭✭Gosh


    If you want to use the fieldname then the following will work if you call each button 'Button..."

    Dim ctl As System.Windows.Forms.Control
    
    For Each ctl In Me.Controls
       If Microsoft.VisualBasic.Left(ctl.Name, 6) = "Button" Then
          ctl.Visible = False
       End If
    Next ctl
    


  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    is there not a "FindControl()" method which takes the control name as a string, and returns the control?

    i.e. Button mybutton = FindControl("myButtonsName");


  • Advertisement
Advertisement