Click here to Skip to main content
15,913,055 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to clear all textboxes on a form with a button Pin
KaptinKrunch9-Mar-08 17:48
KaptinKrunch9-Mar-08 17:48 
AnswerRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 17:41
protectorChristian Graus9-Mar-08 17:41 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:48
Jacob Dixon9-Mar-08 17:48 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:51
Jacob Dixon9-Mar-08 17:51 
AnswerRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 17:50
Ravenet9-Mar-08 17:50 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:54
Jacob Dixon9-Mar-08 17:54 
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 17:58
Ravenet9-Mar-08 17:58 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:03
Jacob Dixon9-Mar-08 18:03 
Ok.. I have a button that is suppose to clear EVERY textbox on my form. That is what I am trying to accomplish! The buttons code is this:

This is EXACTLY what I have:

private void button10_Click(object sender, EventArgs e)
{
    foreach (Control txt in this.Controls)
    {
        if (txt is TextBox)
        {
            txt.Text = string.Empty;
            this.Refresh();
        }
    }


        // Clear all the combo boxes and richtextboxes on the form
        Phone2Listbox.Items.Clear();
        phoneListbox.Items.Clear();
        AuthPhone1Listbox.Items.Clear();
        AuthPhone2Listbox.Items.Clear();
        AuthPhone3Listbox.Items.Clear();
        MedAllergiesListbox.Items.Clear();
        MedPhoneListbox.Items.Clear();
        EmergPhoneListbox.Items.Clear();
        PaidToDateListbox.Items.Clear();
        richTextBox1.Clear();
        othercomments.Clear();
}



I am sorry that I said it was clearing a listbox, that is the code I have above that is clearing the textbox, and richtextbox. I'm tired, so sorry I said that.

The point is, is that it is not clearing the textboxes.. When I load my form I just type random crap in the text boxes and click my button (Clear All) and it doesn't clear the textboxes..

By the way I can't do:
if (txt as TextBox)


It has to be:
if (txt is TextBox)



The reason is, is because when you use the txt AS textbox it throws an exeception:

" Cannot implicity convert type 'System.Windows.Forms.Textbox' to 'bool' "
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 18:07
Ravenet9-Mar-08 18:07 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 17:58
Jacob Dixon9-Mar-08 17:58 
GeneralRe: How to clear all textboxes on a form with a button Pin
Christian Graus9-Mar-08 18:01
protectorChristian Graus9-Mar-08 18:01 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:08
Jacob Dixon9-Mar-08 18:08 
GeneralRe: How to clear all textboxes on a form with a button Pin
Jacob Dixon9-Mar-08 18:10
Jacob Dixon9-Mar-08 18:10 
GeneralRe: How to clear all textboxes on a form with a button Pin
Ravenet9-Mar-08 18:13
Ravenet9-Mar-08 18:13 
QuestionTimer Pin
nelsonpaixao9-Mar-08 15:56
nelsonpaixao9-Mar-08 15:56 
GeneralRe: Timer Pin
Ravenet9-Mar-08 16:33
Ravenet9-Mar-08 16:33 
QuestionDictionary Reset? Pin
Jammer9-Mar-08 13:43
Jammer9-Mar-08 13:43 
GeneralRe: Dictionary Reset? Pin
Christian Graus9-Mar-08 15:01
protectorChristian Graus9-Mar-08 15:01 
GeneralRe: Dictionary Reset? Pin
Jammer9-Mar-08 15:27
Jammer9-Mar-08 15:27 
GeneralRe: Dictionary Reset? Pin
Christian Graus9-Mar-08 15:52
protectorChristian Graus9-Mar-08 15:52 
GeneralRe: Dictionary Reset? Pin
Jammer10-Mar-08 6:14
Jammer10-Mar-08 6:14 
GeneralRe: Dictionary Reset? Pin
Jammer10-Mar-08 9:40
Jammer10-Mar-08 9:40 
GeneralStrange XmlDocument.Save() behaviour when using openfiledialog in Windows Forms Pin
turkel9-Mar-08 12:22
turkel9-Mar-08 12:22 
GeneralRe: Strange XmlDocument.Save() behaviour when using openfiledialog in Windows Forms Pin
Christian Graus9-Mar-08 12:34
protectorChristian Graus9-Mar-08 12:34 
GeneralRe: Strange XmlDocument.Save() behaviour when using openfiledialog in Windows Forms Pin
Lutosław9-Mar-08 12:39
Lutosław9-Mar-08 12:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.