473,395 Members | 1,681 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Access Dynamically created controls on a Form?

Radio Buttons are added to my form During the Load event,
the quantity determined by User input. They are placed in
pairs on groupboxes with code like this: (edited a bit for
brevity)

Public Function LayoutForm(ByVal intNumber As Integer)
Dim intCount As Integer
Panel1.Controls.Clear()
For intCount = 1 To intGames

'Visitors Button
Dim RadioButton1 As System.Windows.Forms.RadioButton
RadioButton1 = New System.Windows.Forms.RadioButton
RadioButton1.Text = GetSchedule(intWeek, "Visitor",
intCount)
RadioButton1.Name = "RadioButtonV" & intCount '+ 1
RadioButton1.Visible = True
Me.Controls.Add(RadioButton1)

'Home Button
Dim RadioButton2 As System.Windows.Forms.RadioButton
RadioButton2 = New System.Windows.Forms.RadioButton
RadioButton2.Text = GetSchedule(intWeek, "Home",
intCount)
RadioButton2.Name = "RadioButtonH" & intCount '+ 1
RadioButton2.Visible = True
'Me.Controls.Add(RadioButton2)

'Group
Dim grp As New System.windows.forms.GroupBox
grp.Top = 40 * count + 10
grp.Left = 25
grp.Height = 40
grp.Width = 500
'grp.SendToFront()
grp.Controls.Add(RadioButton1)
grp.Controls.Add(RadioButton2)
Panel1.Controls.Add(grp)
Next

End Function
This works quite well and lays things out as it should.
However, i have a button ("btnSave") whose click event
collects the Text property of each selected button and
compiles them into an XML file. Well, that is the intent.
I can't seem to get my program to recognize the
RadioButtons as belonging to Me.Controls collection. My
code works when in another portion of the program where i
am collecting data from dynamically created TextBoxes, but
those are not in groups. This is the method i am trying to
use to read the data:
Private Sub btnSave_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnSave.Click
'Save picks for current player
Dim ctl As System.Windows.Forms.Control
Dim radiobtn As System.Windows.Forms.RadioButton
Dim MyPicksDocument As New XmlDocument
Dim xmlPicksData As String
Dim intGameCount As Integer = 1
For Each ctl In Me.Controls
Console.WriteLine(ctl.Text) ' for debugging
If TypeOf ctl Is RadioButton Then
radiobtn = CType(ctl, RadioButton)
'xmlPicksData String building info here
intGameCount +=1
Else
intGameCount += 1
End If
Next

MyPicksDocument.LoadXml(xmlPicksData)
'commands to save file
End Sub

When i run this, and click "Save", the only controls whose
text gets written to the Console window are the ones
placed on the form in the designer. It never hits the
groupboxes or radiobuttons. Is there a way to make them
recognized?

Any help is appreciated.

Nov 20 '05 #1
2 4524
"D Hass" <ju*******@hotmail.com> schrieb

When i run this, and click "Save", the only controls whose
text gets written to the Console window are the ones
placed on the form in the designer. It never hits the
groupboxes or radiobuttons. Is there a way to make them
recognized?


The Form.Controls collection contains only the controls *directly* placed on
the Form, not the nested controls. Put your loop into a procedure and call
it in btnsave_click. Within the for-next loop, to make the sub recursive,
write something like:

if typeof ctl is groupbox then
<nameofthenewsub>(ctl.controls, ...)
elseif typeof ctl is radiobutton then
'current code
end if

Note: The type of the first argument of the new submust be
Control.ControlCollection, not Form.ControlCollection.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
Thank-you, Armin
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Will | last post by:
Hi, I have a problem trying to validate dynamically created html form elements using javascript. I have dynamically created a check box using ASP for each record in a recordset and have given each...
7
by: Gelios | last post by:
Hello all! I have a Windows.Forms code where I dynamically created controls. How can I access to properties from event handler? For example: createSomeControls() { TextBox textBox = new...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
5
by: Amelyan | last post by:
How can I get state of dynamically created controls (RadioButton, CheckBox, TextBox.Text) on post back when I click submit button? The only way I know is by traversing Response.Form enumberator;...
6
by: TB | last post by:
Hi All: I have this page where a rows / cells are programmatically added to to table by pushing a button. The rows contain a textbox and a associated button. What I want to is to be able to...
1
by: Grega | last post by:
Hi all, I am trying to create a VB smart device application. I create few buttons dynamically on form_load... something like this: Dim WithEvents BtnOperate As New...
2
by: Dica | last post by:
i've got a script that creates a new tablerow + tablecell and appends that to a non dynamically created table control. a new row is added for each recordset returned from my sql statement. within...
2
by: Dwight Johnson | last post by:
I am building a website in VS2005. I basically have one page, default.aspx, which contains placeholder objects into which I add various controls that are dynamically created. I have a dropdownlist...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.