1

OK, so, I'm trying to make it if a read-only textbox1 equals some string, then another read-only textbox2 equals some other string, depending on what textbox1 is. For example, it textbox 1 is equal to "Hey" Textbox2 will be equal to "Hi". Here's what I have:

string responseString = "Hey";
if(TextBox1.Text == ("Hi"))
{
    TextBox2.Text = responseString;
}

I'm using Visual studios C# Express 2010. I'm new to this so I'm sorry for any dumb questions. My C# class hasn't gone into too much depth with Strings and loops yet. Thanks!

I'm not getting any errors by the way, it just doesn't work.

7
  • What event have you placed your code in? Commented Mar 21, 2014 at 13:57
  • 2
    You have the strings other way around. Commented Mar 21, 2014 at 13:57
  • 1
    What do you mean view only textboxes? Do you actually mean readonly? Commented Mar 21, 2014 at 13:57
  • Yeah, I'm sorry. I meant read-only. I had it under: private void textBox1_TextChanged(object sender, EventArgs e) Commented Mar 21, 2014 at 14:01
  • 1
    If your textboxes are readonly, how do you think their text will change so the event is fired? Commented Mar 21, 2014 at 14:02

2 Answers 2

3

Your code is currently backwards from what you've described you're trying to do:

string responseString = "Hi";

if (TextBox1.Text == "Hey")
{
    TextBox2.Text = responseString;
}
Sign up to request clarification or add additional context in comments.

2 Comments

I figured it out. I had my code under the wrong event as Ahbi had said. I had in under the wrong textbox event.
@brettsalyer: In that case, the usual answer is to submit your own answer and accept it if you feel that this would be helpful to others.
0
   private void TextBox1_TextChanged(object sender, EventArgs e)
{
    string responseString = "Hi";
    if (TextBox1.Text == ("Hey"))
    {
        TextBox2.Text = responseString;
    }
}

Above is correct. I had it under the: `

private void textBox2_TextChanged(object sender, EventArgs e)

which was not correct.`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.