Solved

Setting an event for an array of radio buttons

Posted on 2011-09-07
7
252 Views
Last Modified: 2012-06-21
My code dynamically creates radio buttons.  How do add a handler to that to point to code?
Dim rbA(16) As RadioButton
        Dim rbH(16) As RadioButton

        For iLoop = 1 To 16

            rbA(iLoop) = New RadioButton
            rbH(iLoop) = New RadioButton

            With rbA(iLoop)

                .Text = "TEST"
                .Checked = False
                .GroupName = "GroupA" & iLoop
                .ID = "Here" & iLoop
                .BackColor = Drawing.Color.SteelBlue

            End With

            Panel1.Controls.Add(rbA(iLoop))

Open in new window

0
Comment
Question by:NOTBOB90
  • 4
  • 2
7 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36499003
Use the AddHanler keyword:
Dim rbA(16) As RadioButton
        Dim rbH(16) As RadioButton

        For iLoop = 1 To 16

            rbA(iLoop) = New RadioButton
            rbH(iLoop) = New RadioButton

            AddHandler rbA(iLoop).CheckChanged, AddressOf Radio_CheckChanged
            AddHandler rbH(iLoop).CheckChanged, AddressOf Radio_CheckChanged

            With rbA(iLoop)

                .Text = "TEST"
                .Checked = False
                .GroupName = "GroupA" & iLoop
                .ID = "Here" & iLoop
                .BackColor = Drawing.Color.SteelBlue

            End With

            Panel1.Controls.Add(rbA(iLoop))

Open in new window

0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 50 total points
ID: 36499011
P.S.

The syntax for AddHandler is:

AddHandler obj.EventName, AddressOf EventHandlerFunctionName
0
 

Author Comment

by:NOTBOB90
ID: 36499025
This is on the web, not .net.  Will it work like that there?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36499118
This is on the web, not .net.  Will it work like that there?
It will add a server-side event handler--though you still need to code the actual handler function. If you want a client-side handler (i.e. javascript), then you would need to use the ScriptManager.
0
 

Author Comment

by:NOTBOB90
ID: 36499827

WHen I do this:

AddHandler rbH(iLoop).CheckChanged, AddressOf proRadioClick

I get this error hovering over checkchanged

checkchanged is not an event of system.web.ui..webcontrols.radiobutton
0
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 36499977
I was just throwing an event out as an example. The correct name is CheckedChanged. See here for more details.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now