Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 27th, 2004, 05:52 PM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Default Using loop to change text of multiple textboxes

I have a few textboxes named textbox1, textbox2, etc. Is there a way to create a loop to change the text in each text box to the same thing by incrementing the number after textbox.
Reply With Quote
  #2 (permalink)  
Old July 27th, 2004, 10:11 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You could using the FindControl("controlname") method. Build the control from "textbox" and the loop counter.
Reply With Quote
  #3 (permalink)  
Old July 28th, 2004, 09:46 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Default

I tried using FindControl() but I am getting the error Name 'FindControl' is not declared. I even copied the example from the help file and got the same error.
Reply With Quote
  #4 (permalink)  
Old July 28th, 2004, 10:43 AM
Authorized User
 
Join Date: Jan 2004
Location: , , .
Posts: 34
Thanks: 0
Thanked 1 Time in 1 Post
Default

The code i am using is:
Code:
  Dim textboxNumber As Control
  Dim x As Integer = 1
  For x = 1 To 9
     textboxNumber = FindControl("textbox" + x)
     textboxNumber.Text = ""
  Next
Reply With Quote
  #5 (permalink)  
Old July 28th, 2004, 11:47 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I responded prematurely to this thread. Are you working in a windows form? Sounds like it. That method applies to web forms. I'm not sure how you'd do this in a windows form apart from putting all the textboxes into some collection or control container so you can loop thru all of that object's members.
Reply With Quote
  #6 (permalink)  
Old July 28th, 2004, 02:47 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , .
Posts: 540
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Try:

_______________________________________

Dim ctrl As Control
For Each ctrl In Me.Controls
   If (ctrl.GetType.ToString = "System.Windows.Forms.TextBox") Then
         CType(ctrl, TextBox).Text = "All textbox text is the same."
   End If
Next

________________________________________

This should get you on the right track. Modify it according to what exactly you want. With this you don't need the number, it just looks to see if the control is a textbox.

The above example is for the entire form, but you can do this for panels, groupboxes, etc., anything that is a container.

J
Reply With Quote
  #7 (permalink)  
Old July 29th, 2004, 08:54 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Also consider the recursion factor. If you encounter a control that contains controls, you'll need to dig into that as well. So you should write this logic into a method that can call itself if it finds controls within a control's controls collection.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
textboxes or list boxes with multiple fore color svharishtech Pro VB 6 5 April 20th, 2007 05:04 PM
Help: character and multiple textboxes snoopy_sweden Javascript How-To 0 February 20th, 2007 04:08 AM
COLOR CHANGE IN TEXTBOXES Rashad Javascript How-To 5 November 28th, 2005 06:06 AM
Validate Multiple Textboxes ~Bean~ ASP.NET 1.0 and 1.1 Professional 2 October 11th, 2005 03:03 PM
Replace textboxes or textareas with some text amit_bhatia Beginning PHP 1 December 7th, 2004 11:32 AM



All times are GMT -4. The time now is 05:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.