Solved

dynamic controls not loading?

Posted on 2014-03-24
3
145 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
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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