?
Solved

Setting an event for an array of radio buttons

Posted on 2011-09-07
7
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 75

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 75

Accepted Solution

by:
käµfm³d   👽 earned 200 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 75

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 75

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
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.
Suggested Courses

770 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