Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

dynamic controls not loading?

Posted on 2014-03-24
3
Medium Priority
?
163 Views
Last Modified: 2014-03-24
I am trying to load a GroupBox control with RadioButtons. The first rdo shows up fine but the other ones do not. I know I'm missing something because I've done this before. Unfortunately I don't have the old code to reference back to. Here is what I have so far.

                Private WithEvents rdo As RadioButton

                For Each itm In EH.eCol
                    arr = Split(itm, ",")

                    If arr.Length > 1 Then
                        rdo = New RadioButton
                        rdo.Tag = arr(0)
                        rdo.Text = arr(1)
                        rdo.Name = arr(1)
                        rdo.Font = New Font(rdo.Font.Name, rdo.Font.Size, Drawing.FontStyle.Regular)

                        cnt += 1

                        Select Case cnt
                            Case 1
                                startYPos = yRow1
                            Case 2
                                startYPos = xCol2
                                startXPos = leftXPos
                            Case 3
                                startYPos += rdo.Height
                                startXPos += rdo.Height
                                cnt = 0
                        End Select

                        rdo.Top = startXPos
                        rdo.Left = startYPos

                        AddHandler rdo.Click, AddressOf rdo_Click

                        grpStandards.Controls.Add(rdo)
                    End If
                Next

Open in new window

0
Comment
Question by:BlakeMcKenna
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 39951798
Do not declare your RadioButton at the Form level. Since you are using the same variable for all the buttons, you can end up losing what's in there every time that you call New on the variable. Since you are using AddHandler, you do not need WithEvents.

  For Each itm In EH.eCol
                    Dim rdo As RadioButton
                    arr = Split(itm, ",")

Also, step through your code in the debugger to make sure that it loops more than once.
0
 
LVL 15

Assisted Solution

by:ChloesDad
ChloesDad earned 1000 total points
ID: 39951844
Also check that you are not putting the buttons on top of each other. The code to set the positions looks like it could be wrong, but without knowing where the buttons are meant to go I can't say for certain.

Also Shouldn't

   startXPos += rdo.Height


be

   startXPos += rdo.Width
0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39951910
James,

I actually figured it out. It was my alignment but your suggestions in the declaration are good and I will recode it.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

972 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