Solved

dynamic controls not loading?

Posted on 2014-03-24
3
151 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
[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
3 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 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 250 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

752 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