473,604 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(ByVa l intNumber As Integer)
Dim intCount As Integer
Panel1.Controls .Clear()
For intCount = 1 To intGames

'Visitors Button
Dim RadioButton1 As System.Windows. Forms.RadioButt on
RadioButton1 = New System.Windows. Forms.RadioButt on
RadioButton1.Te xt = GetSchedule(int Week, "Visitor",
intCount)
RadioButton1.Na me = "RadioButto nV" & intCount '+ 1
RadioButton1.Vi sible = True
Me.Controls.Add (RadioButton1)

'Home Button
Dim RadioButton2 As System.Windows. Forms.RadioButt on
RadioButton2 = New System.Windows. Forms.RadioButt on
RadioButton2.Te xt = GetSchedule(int Week, "Home",
intCount)
RadioButton2.Na me = "RadioButto nH" & intCount '+ 1
RadioButton2.Vi sible = True
'Me.Controls.Ad d(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.SendToFron t()
grp.Controls.Ad d(RadioButton1)
grp.Controls.Ad d(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(B yVal sender As System.Object,
ByVal e As System.EventArg s) Handles btnSave.Click
'Save picks for current player
Dim ctl As System.Windows. Forms.Control
Dim radiobtn As System.Windows. Forms.RadioButt on
Dim MyPicksDocument As New XmlDocument
Dim xmlPicksData As String
Dim intGameCount As Integer = 1
For Each ctl In Me.Controls
Console.WriteLi ne(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(xmlPic ksData)
'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 4540
"D Hass" <ju*******@hotm ail.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
<nameofthenewsu b>(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.Control Collection, not Form.ControlCol lection.
--
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
3182
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 a unique ID using the primary key from a db table. e.g "chk" + "1" for record 1 and "chk" + "2" for record 2 etc. This means each box is called chk1 and chk2 respectively. This works fine and changes dependant on the recordset used and allows me...
7
2716
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 TextBox(); Button doSomeAction = new Button(); doSomeAction.Click += new EventHandler(doSomeAction_Click);
1
3013
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 web page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g....
1
2562
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 page dynamically. To do this, First I including a web page (MainPage.aspx) and I made form tag to Runat=Server. I included one table tag and also made this table Runat=Server side. Second I created three Web User Controls e.g. wucCustomerInfo.ascx,
5
3506
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; Response.Form.GetEnumerator(), etc. while, identifying specific controls by programmatically assigned unique id (e.g. MyButton_AnswerID_123). However, I am not sure if that is the proper way. What is the common practice?
6
1788
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 add the content of any textbox to a global variable (and a related session variable) when pushing the associate button. However whenever I push the button(s) apparently the session variable
1
1877
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 OpenNETCF.Windows.Forms.Button2 Me.BtnOperate.Location = New System.Drawing.Point(20, 20) Me.BtnOperate.Size = New System.Drawing.Size(150, 150) Me.BtnOperate.TabIndex = 0 Me.Controls.Add(Me.BtnOperate)
2
2224
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 each tablecell, i place a dynamically created checkbox control. i now need to fetch back the value of the checkbox as follows: foreach (Control c in tblServices.Controls) { } this doesn't work, however. if i step through with the debugger,...
2
1387
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 that is created in the InitializeComponent event so I can do a FindControl on it later to determine its new value when it is selected. Based on this new value I will then get data from a database and fill another placeholder on the page with a...
0
8409
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8065
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6739
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5882
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3955
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.