473,394 Members | 1,821 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,394 software developers and data experts.

Controls collection

I am adding controls to the Forms controls collection at run-time.
Then when I loop through the controls and list them by name, I am
missing half my controls. Is there a workaround?

Debugger output while adding

shiftmrk0 Added
shiftmrk1 Added
shiftmrk2 Added
shiftmrk3 Added
shiftmrk4 Added

Debugger output while looping through the forms controls() collection

shiftmrk0
shiftmrk2
shiftmrk4

All controls are children of the Form, no panels or tab controls.

Jul 6 '06 #1
3 1281
Post your code for both adding the controls, and listing them by name.

"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@j8g2000cwa.googlegro ups.com...
>I am adding controls to the Forms controls collection at run-time.
Then when I loop through the controls and list them by name, I am
missing half my controls. Is there a workaround?

Debugger output while adding

shiftmrk0 Added
shiftmrk1 Added
shiftmrk2 Added
shiftmrk3 Added
shiftmrk4 Added

Debugger output while looping through the forms controls() collection

shiftmrk0
shiftmrk2
shiftmrk4

All controls are children of the Form, no panels or tab controls.

Jul 6 '06 #2
For i as integer = 0 to 4
Dim mrk as new Label
lbl.name = "shiftmrk" & i
me.controls.add(mrk)
Debug.writeline(mrk.name & " Added")
Next

For each ctrl as Control In Me.Controls()
If Not ctrl is Nothing
If ctrl.gettype is gettype(Label)
ctrl.dispose
debug.writeline(mrk.name & " Removed")
End If
End If
Next

Typed this by hand quick, but my code is the same.
Brendan Green wrote:
Post your code for both adding the controls, and listing them by name.

"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@j8g2000cwa.googlegro ups.com...
I am adding controls to the Forms controls collection at run-time.
Then when I loop through the controls and list them by name, I am
missing half my controls. Is there a workaround?

Debugger output while adding

shiftmrk0 Added
shiftmrk1 Added
shiftmrk2 Added
shiftmrk3 Added
shiftmrk4 Added

Debugger output while looping through the forms controls() collection

shiftmrk0
shiftmrk2
shiftmrk4

All controls are children of the Form, no panels or tab controls.
Jul 6 '06 #3
I have found a temp solution to the problem, although there must be a
better way. I added enlosed the For...Next in another loop and cycle
through it once more.

For i as integer = 0 to 1
For each ctrl as Control In Me.Controls()
If Not ctrl is Nothing
If ctrl.gettype is gettype(Label)
ctrl.dispose
debug.writeline(mrk.name & " Removed")
End If
End If
Next
Next

This removes all controls, but it shouldn't have to be done this way.

Charlie Brown wrote:
For i as integer = 0 to 4
Dim mrk as new Label
lbl.name = "shiftmrk" & i
me.controls.add(mrk)
Debug.writeline(mrk.name & " Added")
Next

For each ctrl as Control In Me.Controls()
If Not ctrl is Nothing
If ctrl.gettype is gettype(Label)
ctrl.dispose
debug.writeline(mrk.name & " Removed")
End If
End If
Next

Typed this by hand quick, but my code is the same.
Brendan Green wrote:
Post your code for both adding the controls, and listing them by name.

"Charlie Brown" <cb****@duclaw.comwrote in message
news:11**********************@j8g2000cwa.googlegro ups.com...
>I am adding controls to the Forms controls collection at run-time.
Then when I loop through the controls and list them by name, I am
missing half my controls. Is there a workaround?
>
Debugger output while adding
>
shiftmrk0 Added
shiftmrk1 Added
shiftmrk2 Added
shiftmrk3 Added
shiftmrk4 Added
>
Debugger output while looping through the forms controls() collection
>
shiftmrk0
shiftmrk2
shiftmrk4
>
All controls are children of the Form, no panels or tab controls.
>
Jul 6 '06 #4

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

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
2
by: Das | last post by:
Hi All, Where does asp.net stores the objects declared in the page. I have a method where I want to loop through all the controls(textbox, HtmlInputText) within the page. I want to in which...
9
by: Merlin | last post by:
Hi, My code below doesn't work does anyone have any pointers? All my controls are programically added. Dim i As Int16 For i = 0 To Me.Controls.Count - 1 If Me.Controls(i).Name <>...
66
by: Cor | last post by:
Hi, I start a new thread about a discussion from yesterday (or for some of us this morning). It was a not so nice discussion about dynamically removing controls from a panel or what ever. It...
6
by: Peter Zolja | last post by:
Hi, I'm building a webcontrol that contains a dynamic list of other controls. My problem is that when I add or remove an item the synchronization between the ViewState and the Controls...
15
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)...
0
by: rn5a | last post by:
Suppose I have the following DataGrid: <asp:DataGrid ID="dgUsers" OnUpdateCommand="UpdateDG" runat="server"> <Columns> <TemplateColumn HeaderText="NAME"> <ItemTemplate> <asp:Label...
3
by: Nunzio | last post by:
I am trying to add specific form controls to a VBA collection, so that I can pass the entire collection to another function, and access the individual controls later. I have tried several...
32
by: =?Utf-8?B?U2l2?= | last post by:
I have a form that I programmatically generate some check boxes and labels on. Later on when I want to draw the form with different data I want to clear the previously created items and then put...
9
by: dhtml | last post by:
I have written an article "Unsafe Names for HTML Form Controls". <URL: http://jibbering.com/faq/names/ > I would appreciate any reviews, technical or otherwise. Garrett --...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.