Results 1 to 9 of 9

Thread: Since there are no more control arrays...

  1. #1

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360

    Since there are no more control arrays...

    If I have some RadioButtons and want to change all of their text properties using a subroutine, but how do I loop thru all of them?

    Thanks.

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Good question...
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3
    Addicted Member Sheppe's Avatar
    Join Date
    Sep 2002
    Location
    Kelowna, BC
    Posts
    245
    Use the tag property of the control. In this case I've set the tag of the group of radiobuttons to "RB1".

    VB Code:
    1. Dim CTRL As Control
    2.  
    3.         For Each CTRL In Me.Controls
    4.             If TypeOf (CTRL) Is RadioButton Then
    5.                 If CTRL.Tag = "RB1" Then
    6.                     CTRL.Text = "RB1"
    7.                 End If
    8.             End If
    9.         Next
    [vbcode]
    On Error Goto Hell
    [/vbcode]
    Sheppe Pharis, MCSD
    Check out http://www.vb-faq.com
    Click here for access to the free Code-Express source code and component sharing network for VB6
    Want a better way to skin your .NET applications? Click here!

  4. #4

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    Yeah I already hardcoded EACH of the text properties and tags. But each time I click one of the Radios I get a sub with the name of the Radio i.e.

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

    End Sub

    So my question now is,
    HOW THE HELL DO I WRITE A SUB THAT 'KNOWS' WHICH RADIOBUTTON WAS SELECTED?

    Sorry people Im not crabbing at yall but this is frustrating. I just started yesterday with VB.Net

  5. #5
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    You can write one onClick handler for each "group" of radiobuttons that sets a variable to which one is selected.

    PHP Code:
    Private rdbSet As System.Windows.Forms.RadioButton


            
    Private Sub radiobutton_Click(ByVal sender As ObjectByVal e As EventArgsHandles rdbBottom.ClickrdbFill.ClickrdbLeft.ClickrdbRight.ClickrdbTop.ClickrdbNone.Click
                rdbSet 
    CType(senderRadioButton)
                
    ApplyChanges()
            
    End Sub

    Private Sub ApplyChanges()

             
                
    'Apply Docking settings - one only
                If rdbSet Is rdbNone Then
                    btnDemo.Dock = System.Windows.Forms.DockStyle.None
                ElseIf rdbSet Is rdbTop Then
                    btnDemo.Dock = System.Windows.Forms.DockStyle.Top
                ElseIf rdbSet Is rdbLeft Then
                    btnDemo.Dock = System.Windows.Forms.DockStyle.Left
                ElseIf rdbSet Is rdbBottom Then
                    btnDemo.Dock = System.Windows.Forms.DockStyle.Bottom
                ElseIf rdbSet Is rdbRight Then
                    btnDemo.Dock = System.Windows.Forms.DockStyle.Right
                Else ' 
    The default is: if (rdbSet is rbFill)
                    
    btnDemo.Dock System.Windows.Forms.DockStyle.Fill
                End 
    If

            
    End Sub 
    -Shurijo

  6. #6

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    Oh man! I got it working. Thanks a lot!

  7. #7

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360
    I got it working but I have a few q's

    what does ByVal e As EventArgs pass to the function?
    what does the CType function return?

  8. #8
    Addicted Member
    Join Date
    Aug 1999
    Posts
    164
    I'm not a guru, but these are my personal thoughts about it.

    >> what does ByVal e As EventArgs pass to the function?

    I think this is just the actual event, sorta like having the location where (x,y) the event happened, which mouse button was clicked, etc.

    >> what does the CType function return?

    RadioButton - The CType function returns type of the second parameter.

    Sender is just an object, so in order to get radiobutton properties we need to convert it to a radiobutton. If Sender was a textbox, this line of code would probably error.
    -Shurijo

  9. #9

    Thread Starter
    Hyperactive Member Radames's Avatar
    Join Date
    Feb 2001
    Location
    Tech Tropics
    Posts
    360

    Talking

    Thanks a lot guy!

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