i have a form that calculate student marks and grade. there is one text box on the form which am finding it difficult reset or clear the text in that textbox. i just double clicked the text box put this code behind it. it is working alright but i cant use

this.txtFcs_exams.Text = "";

to clear the textbox. please help me out. when clearing the screen i get an error message "input string was not in a correct format"

private void txtFcs_exams_TextChanged(object sender, EventArgs e)
        {

            try
            {


                    double classworkFcs, iaFcs, examsFcs, totalsFcs;

                    classworkFcs = Convert.ToDouble(txtFcs_classwork.Text);
                    iaFcs = Convert.ToDouble(txtFcs_ia.Text);
                    examsFcs = Convert.ToDouble(txtFcs_exams.Text);

                    totalsFcs = classworkFcs + iaFcs + examsFcs;
                    txtFcs_totals.Text = totalsFcs.ToString();

                    if (totalsFcs >= 75)
                    {
                        txtFcs_grading.Text = "   A";
                    }
                    else if (totalsFcs >= 70)
                    {
                        txtFcs_grading.Text = "   B";
                    }
                    else if (totalsFcs >= 65)
                    {
                        txtFcs_grading.Text = "   C";
                    }
                    else if (totalsFcs >= 55)
                    {
                        txtFcs_grading.Text = "   D";
                    }
                    else if (totalsFcs >= 45)
                    {
                        txtFcs_grading.Text = "   E";
                    }
                    else
                    {
                        txtFcs_grading.Text = "   F";
                    }

            }
            catch (System.FormatException fmtE)
            {
                MessageBox.Show(fmtE.Message);
            }


        }

Edited 4 Years Ago by mikeoabban: important

When exactly do you wanna clear it? When you click on it, or double click on it?
PS: Create specific event where you wanna do that exactly.

Ok, I am going to own up to just really getting into C#, so I am hoping that I am not too far off.

I am reading this where when you click on the textbox itself - you want it to clear?
If you are wanting to clear the textbox when you click on it - maybe try

this.Text = " ";

Since you are already focused on the element you want to clear - you mentioned that you clicked on the text box to see your code run/results.

or if you want to use another way, such as a button to clear the text - maybe try

public void button_Click(object sender, RoutedEventArgs e)
{
txtFcs_exams.Text = " ";
}

Let me know if I am 1. understanding correctly and 2. close to the mark on my thinking (no, haven't tested them, I know I know... bad bad coder , bad)

This article has been dead for over six months. Start a new discussion instead.