0

I have a text box designTB and a double variable totaldsgn.
I cannot create the following equation because the designTB is a string and totaldsgn is a double

designTB.Text = totaldsgn

I have tried this and it still does not work

designTB.Text = totaldsgn.tostring

Any suggestions? Is there a way to make a text box a double instead of a string?

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by MJV
0

Without databinding you need to validate the input yourself:

private void button1_Click(object sender, EventArgs e)
    {
      //Set the value
      double d1 = 5.0;
      textBox1.Text = Convert.ToString(d1);
    }

    private void button2_Click(object sender, EventArgs e)
    {
      //read the value
      double d1;
      if (!double.TryParse(textBox1.Text, out d1))
      {
        textBox1.Focus();
        textBox1.SelectAll();
        MessageBox.Show("Invalid value");
        return;
      }
      //Continue with code...
    }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.