Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > Pro VB.NET 2002/2003
|
Pro VB.NET 2002/2003 For advanced Visual Basic coders working .NET version 2002/2003. Beginning-level questions will be redirected to other forums, including Beginning VB.NET.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB.NET 2002/2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2004, 09:58 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Set all textboxes to ReadOnly

Hi there...

I have a form with lots of textboxes and i have to set readonly, all of them, true and false many times.

How can i make a Sub to do that? ...like this one to clear them.

Public Sub limpaTXT(ByVal nomeForm As System.Object)
        Dim MeuControl As Control

        For Each MeuControl In nomeForm.Controls
            If TypeOf MeuControl Is TextBox Then
                MeuControl.Text = ""
            End If
        Next MeuControl
End Sub

TKS
nobreferreira@sapo.pt

 
Old October 15th, 2004, 10:49 AM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Public Sub TxtReadOnly(ByVal nomeForm As System.Object)
Dim MeuControl As Control

For Each MeuControl In nomeForm.Controls
If TypeOf MeuControl Is TextBox Then
MeuControl.Readonly = True
End If
Next MeuControl
End Sub

the tricky part is if you only need to set certain textboxes and not all of them at once, but you do this in a select case


Duncan
 
Old October 15th, 2004, 11:08 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi again

i've already tried that.
It looked like the obvious solution but it get this error:

'Readonly' is not a member of 'System.Windows.Forms.Control'

    Public Sub TxtReadOnly(ByVal nomeForm As System.Object)
        Dim MeuControl As Control

        For Each MeuControl In nomeForm.Controls
            If TypeOf MeuControl Is TextBox Then
                MeuControl.Readonly = True <------- right here
            End If
        Next MeuControl
    End Sub

TKS

 
Old October 15th, 2004, 11:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

    For Each MeuControl In nomeForm.Controls
            If TypeOf MeuControl Is TextBox Then
                CType(MeuControl, TextBox).ReadOnly = True
            End If
        Next MeuControl
    End Sub

Brian
 
Old October 15th, 2004, 11:51 AM
Registered User
 
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Doesn't work :(

MSN: nobreferreira@iol.pt
 
Old October 15th, 2004, 01:00 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Are the txtboxes in a container, such as a panel? If they are, make reference to the panel and loop through the controls property on that:

For each MeuControl In nomeForm.Panel1.Controls

Brian
 
Old October 15th, 2004, 01:02 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Also, if you are getting an error, post that too.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset is readonly vb.net-newbie ADO.NET 1 May 8th, 2007 11:12 AM
readonly checkbox Dj Kat HTML Code Clinic 3 November 10th, 2006 08:34 AM
apply the 'readonly' attribute to all textboxes crmpicco CSS Cascading Style Sheets 9 April 26th, 2006 05:26 AM
How to set textbox property to readonly when text bekim Classic ASP Basics 1 July 12th, 2005 12:06 AM
Readonly checkbox nerssi HTML Code Clinic 1 May 20th, 2005 06:28 AM





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