Author |
Message |
AS I #1 / 11
|
 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 |
|
 |
Wiktor Zychl #2 / 11
|
 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 |
|
 |
AS I #3 / 11
|
 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 |
|
 |
Joe Glove #4 / 11
|
 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 |
|
 |
Armin Zingle #5 / 11
|
 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 |
|
 |
AS I #6 / 11
|
 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 |
|
 |
Andy #7 / 11
|
 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 |
|
 |
AS I #8 / 11
|
 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
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 |
|
 |
Armin Zingle #9 / 11
|
 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 |
|
 |
Armin Zingle #10 / 11
|
 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 |
|
 |
AS I #11 / 11
|
 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 |
|
|