Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Clear textbox problem

Clear textbox problem

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rick van Woudenberg
    wrote on last edited by
    #1

    Dear all, I wrote this piece of code to clear all the textboxes on a control all at once. foreach (Control control in tabpage.Controls) { if (control.GetType() == typeof(TextBox)); { control.Text = ""; } } It works , but .. it also clears all the labels in the control ; however labels are not of type Textbox. Could somebody tell me what I am doing wrong ? kind regards,

    R E 2 Replies Last reply
    0
    • R Rick van Woudenberg

      Dear all, I wrote this piece of code to clear all the textboxes on a control all at once. foreach (Control control in tabpage.Controls) { if (control.GetType() == typeof(TextBox)); { control.Text = ""; } } It works , but .. it also clears all the labels in the control ; however labels are not of type Textbox. Could somebody tell me what I am doing wrong ? kind regards,

      R Offline
      R Offline
      Rick van Woudenberg
      wrote on last edited by
      #2

      Addition to the previous post ... this works : for (int i = 0; i < this.Controls.Count; i++ ) { if (this.Controls[i] is TextBox) { this.Controls[i].Text = ""; } } I'm puzzled now :confused:

      G 1 Reply Last reply
      0
      • R Rick van Woudenberg

        Addition to the previous post ... this works : for (int i = 0; i < this.Controls.Count; i++ ) { if (this.Controls[i] is TextBox) { this.Controls[i].Text = ""; } } I'm puzzled now :confused:

        G Offline
        G Offline
        Gareth H
        wrote on last edited by
        #3

        Rick van Woudenberg,

        foreach (Control control in Controls)
        {
        if (control is TextBox)
        {
        TextBox textBox = control as TextBox;
        textBox.Text = string.Empty;
        }
        }

        Regards, Gareth.

        1 Reply Last reply
        0
        • R Rick van Woudenberg

          Dear all, I wrote this piece of code to clear all the textboxes on a control all at once. foreach (Control control in tabpage.Controls) { if (control.GetType() == typeof(TextBox)); { control.Text = ""; } } It works , but .. it also clears all the labels in the control ; however labels are not of type Textbox. Could somebody tell me what I am doing wrong ? kind regards,

          E Offline
          E Offline
          engsrini
          wrote on last edited by
          #4

          Hi remove the semicolon on the following statement if (control.GetType() == typeof(TextBox)); then it should work Regards Srini

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups