Solved

dynamic controls not loading?

Posted on 2014-03-24
3
137 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Visual Studio 2013 Shortcut (VB) 4 46
.NET 2008 VB and C# 6 28
Expression Evaluater 3 25
vb.net winforms sizing/resolution? 4 33
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

777 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