Solved

dynamic controls not loading?

Posted on 2014-03-24
3
130 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 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

16 Experts available now in Live!

Get 1:1 Help Now