TypeOf doesn't work 
Author Message
 TypeOf doesn't work

Hi All,

My TypeOf doen't work. It generates no error, but can't clear those TextBox.
Do I miss something? Thanks for any tip.

Kind regards,
AS

    Dim CTRL As Control

    For Each CTRL In Me.Controls
      If TypeOf CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
    Next



Tue, 26 Apr 2005 19:05:26 GMT  
 TypeOf doesn't work

Quote:
>     For Each CTRL In Me.Controls
>       If TypeOf CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
>     Next

try this:

     For Each CTRL In Me.Controls
       If  CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
     Next

just omit the "TypeOf" keyword (at least in C#).



Tue, 26 Apr 2005 19:39:35 GMT  
 TypeOf doesn't work
Thanks Wiktor,

But won't work in VB.Net:
"TextBox" is a type in "Forms" and cannot be used as expression.


Quote:
> >     For Each CTRL In Me.Controls
> >       If TypeOf CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
> >     Next

> try this:

>      For Each CTRL In Me.Controls
>        If  CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
>      Next

> just omit the "TypeOf" keyword (at least in C#).



Tue, 26 Apr 2005 19:47:51 GMT  
 TypeOf doesn't work
The code snippet you posted works fine for me (as it should - the syntax is
spot on)

Quote:

> Hi All,

> My TypeOf doen't work. It generates no error, but can't clear those
TextBox.
> Do I miss something? Thanks for any tip.

> Kind regards,
> AS

>     Dim CTRL As Control

>     For Each CTRL In Me.Controls
>       If TypeOf CTRL Is System.Windows.Forms.TextBox Then CTRL.Text = ""
>     Next



Tue, 26 Apr 2005 20:21:25 GMT  
 TypeOf doesn't work

Quote:
> Hi All,

> My TypeOf doen't work. It generates no error, but can't clear
> those TextBox. Do I miss something? Thanks for any tip.

> Kind regards,
> AS

>     Dim CTRL As Control

>     For Each CTRL In Me.Controls
>       If TypeOf CTRL Is System.Windows.Forms.TextBox Then
> CTRL.Text = ""
>     Next

Are the textboxes really on the form or boxed in another control?

Armin



Tue, 26 Apr 2005 20:22:25 GMT  
 TypeOf doesn't work
The textboxes are really on the form, but text remain the same.

The code is also OK for others.


Quote:

> > Hi All,

> > My TypeOf doen't work. It generates no error, but can't clear
> > those TextBox. Do I miss something? Thanks for any tip.

> > Kind regards,
> > AS

> >     Dim CTRL As Control

> >     For Each CTRL In Me.Controls
> >       If TypeOf CTRL Is System.Windows.Forms.TextBox Then
> > CTRL.Text = ""
> >     Next

> Are the textboxes really on the form or boxed in another control?

> Armin



Tue, 26 Apr 2005 21:44:59 GMT  
 TypeOf doesn't work
There is nothing wrong with your code but if the textbox is contained by
another control (e.g. panel, tab control), then your code will not access
it. You'll need to recursively iterate over the controls collection of all
the controls.

'e.g.
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
        ClearTextBoxes(Me)
    End Sub

    Private Sub ClearTextBoxes(ByVal rootControl As Control)
        Dim child As Control

        For Each child In rootControl.Controls
            If TypeOf child Is System.Windows.Forms.TextBox Then
                child.Text = String.Empty
            Else
                ClearTextBoxes(child)
            End If
        Next
    End Sub

Quote:

> The textboxes are really on the form, but text remain the same.

> The code is also OK for others.




> > > Hi All,

> > > My TypeOf doen't work. It generates no error, but can't clear
> > > those TextBox. Do I miss something? Thanks for any tip.

> > > Kind regards,
> > > AS

> > >     Dim CTRL As Control

> > >     For Each CTRL In Me.Controls
> > >       If TypeOf CTRL Is System.Windows.Forms.TextBox Then
> > > CTRL.Text = ""
> > >     Next

> > Are the textboxes really on the form or boxed in another control?

> > Armin



Tue, 26 Apr 2005 22:10:05 GMT  
 TypeOf doesn't work
Thanks Andy,

Right, all TextBoxes are inside Frame!


Quote:
> There is nothing wrong with your code but if the textbox is contained by
> another control (e.g. panel, tab control), then your code will not access
> it. You'll need to recursively iterate over the controls collection of all
> the controls.

> 'e.g.
>     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
>         ClearTextBoxes(Me)
>     End Sub

>     Private Sub ClearTextBoxes(ByVal rootControl As Control)
>         Dim child As Control

>         For Each child In rootControl.Controls
>             If TypeOf child Is System.Windows.Forms.TextBox Then
>                 child.Text = String.Empty
>             Else
>                 ClearTextBoxes(child)
>             End If
>         Next
>     End Sub




- Show quoted text -

Quote:
> > The textboxes are really on the form, but text remain the same.

> > The code is also OK for others.




> > > > Hi All,

> > > > My TypeOf doen't work. It generates no error, but can't clear
> > > > those TextBox. Do I miss something? Thanks for any tip.

> > > > Kind regards,
> > > > AS

> > > >     Dim CTRL As Control

> > > >     For Each CTRL In Me.Controls
> > > >       If TypeOf CTRL Is System.Windows.Forms.TextBox Then
> > > > CTRL.Text = ""
> > > >     Next

> > > Are the textboxes really on the form or boxed in another control?

> > > Armin



Tue, 26 Apr 2005 22:35:39 GMT  
 TypeOf doesn't work

Quote:
> The textboxes are really on the form, but text remain the same.

> The code is also OK for others.

Please try:

Quote:
> > >     Dim CTRL As Control

> > >     For Each CTRL In Me.Controls

            debug.writeline ctrl.gettype.fullname

Quote:
> > >     Next

Armin


Tue, 26 Apr 2005 22:39:44 GMT  
 TypeOf doesn't work


Quote:
> Thanks Andy,

> Right, all TextBoxes are inside Frame!


"The textboxes are really on the form, but text remain the same."

;-)

Armin



Tue, 26 Apr 2005 23:19:44 GMT  
 TypeOf doesn't work
Sorry for my en :-)
They are on the form, but 1st within GroupBox (Frame)


Quote:


> > Thanks Andy,

> > Right, all TextBoxes are inside Frame!


> "The textboxes are really on the form, but text remain the same."

> ;-)

> Armin



Tue, 26 Apr 2005 23:56:40 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. fRefreshLinks Doesn't work if path doesn't exist

2. Windows Service Calling VB6 dll doesn't work but works with VB6

3. IE3 doesn't work after working with webbrowser control

4. Why LoadPicture() works on local pathes and doesn't work on the URLS

5. Work Around doesn't work for RichTextBox

6. Passing a Parameter its works and it doesn't work

7. Works/Doesn't Work

8. ActiveX-Exe: .Value=True doesn't work while direct click on button works

9. 'Next Comment' doesn't work

10. Code doesn't work (from Dev's site)

11. WebResponse Webbot Doesn't work with ASP's

12. You'd think this works, but it doesn't

 

 
Powered by phpBB® Forum Software