Results 1 to 6 of 6

Thread: Clear Textboxes on forms

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    49

    Clear Textboxes on forms

    Hello,

    How can I clear textboxes on a form other than like this....

    txtProductID.Text = ""
    txtProductName.Text = ""
    txtQtyPerUnit.Text = ""

    if I have 225 textboxes on several pageframes in an application this would take forever. Is not there a way to setall textboxes.text = ""?


    FoxT

    Always lookin' for an easier way!

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    here's one of many ways ...
    VB Code:
    1. Dim ctl As Control
    2.         For Each ctl In Controls
    3.             If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
    4.                 ctl.Text = ""
    5.             End If
    6.         Next
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    49

    Another question

    dynamic_sysop,

    That looks like a good way to do this, however it did not work in my app. I'm using the native VB.net textboxes with the text property. Do have have to modify something for this. They do clear when I issue this...

    txtProductID.Text = ""
    txtProductName.Text = ""
    txtQtyPerUnit.Text = ""


    FoxT

    Always lookin' for an easier way!

  4. #4
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    VB Code:
    1. Dim ctl As TextBox
    2.         For Each ctl In Me.Controls
    3.                 ctl.Text = ""
    4.         Next
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    49

    Not there yet.

    Ok, here is where I am at now.

    I cannot get this routine to work on any of my applications...

    Dim ctl As TextBox
    For Each ctl In Me.Controls
    ctl.Text = ""
    Next


    however I can get this one to work on a regular form...

    Dim ctl As Control
    For Each ctl In Controls
    If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
    ctl.Text = ""
    End If
    Next

    but what I need is to clear a form with a pageframe. And to clear all textboxes on the different tabs on the pageframe.

    Thanks,

    FoxT

    Always lookin' for an easier way!

  6. #6

    Thread Starter
    Member
    Join Date
    Mar 2004
    Posts
    49

    Talking I got it now

    Ok, I have it now.


    Dim ctl As Control
    For Each ctl In TabPage1.Controls
    If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
    ctl.Text = ""
    End If
    Next
    For Each ctl In TabPage2.Controls
    If ctl.GetType.IsAssignableFrom(GetType(TextBox)) Then
    ctl.Text = ""
    End If
    Next

    Thanks,

    FoxT

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width