3 Replies - 260 Views - Last Post: 26 December 2012 - 08:52 AM Rate Topic: -----

#1 TheJoy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-December 12

Clearing textboxes of displayed form

Posted 26 December 2012 - 08:02 AM

Hi, hope you all had good times with you families this holyday!

I'm looking for a better/cleaner way to clear all textboxes and radiobuttons on the currently visible form(that has control)

The way I know to do it is :

        ' Main form is called "Main" and other pages are called "Page1" trough "Page10"
    If ComboBox1.SelectedIndex = "1" Then
        Page1.textbox1.text = ""
        Page1.textbox2.text = ""
        '...
        Page1.textbox11.text = ""
        Page1.textbox12.text = ""
        Page1.radiobutton1.checked = False
        Page1.radiobutton2.checked = false
        '...
        End If
        If ComboBox1.SelectedIndex = "2" Then
        Page2.textbox1.text = ""
        Page2.textbox2.text = ""
        '... (you see the pathern :P/> )



I just can't find a way to do. I can't find a way to refer to textboxes in a specific form without directly naming it.

Any help, code, hint is much appreciated!
Thank you,

TheJoy

Is This A Good Question/Topic? 0
  • +

Replies To: Clearing textboxes of displayed form

#2 TheJoy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 16-December 12

Re: Clearing textboxes of displayed form

Posted 26 December 2012 - 08:07 AM

:( I can't find the edit button...

I forgot to say that the Page1 , Page2, Page3 ... forms are displayed into Panel1 of the Main form and user select into ComboBox1 a Page(x) to display and modify.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is online

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5316
  • View blog
  • Posts: 11,356
  • Joined: 02-June 10

Re: Clearing textboxes of displayed form

Posted 26 December 2012 - 08:13 AM

You could loop through all the .Controls of the form. .Controls is the collection of controls that exist on a form.

C# - you can use it as psuedo code if you like
foreach(control c in Page1.Controls)
{
   if (g.GetType == Typeof(Textbox)
   {
      ((TextBox)c).Text = string.empty;
   }
}


The real problem you have here though is bad design. Your main form should not know of any of those controls on other forms. At most your main form should just issue an order to the form to clear and have the form take care of its self. In other words Mommy tells the child to clean its room. Mommy does not clean the child's room for them.

From the MainForm
Page1.DoResetForm();
  Page2.DoResetForm();

Was This Post Helpful? 0
  • +
  • -

#4 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 166
  • Joined: 18-October 12

Re: Clearing textboxes of displayed form

Posted 26 December 2012 - 08:52 AM

View PosttlhIn`toq, on 26 December 2012 - 08:13 AM, said:

Mommy does not clean the child's room for them.


Best analogy ever. /Hat
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1