Hello,
I'm trying to make listbox show a few string and double values when button is pressed.
However, I'm getting errors: Cannot implicitly convert type 'string' to 'double' When ever I put double agestr = ageText.Text;
How can I make it so agestr and teethstr text box only accepts double values?
private void addButton_Click(object sender, EventArgs e)
{
string namestr = nameText.Text;
string agestr = ageText.Text; //This needs to be double, not string
string genderstr = genderList.Text;
string teethstr = teethText.Text; //This needs to be double, not string
string tailstr = tailText.Text;
string row = String.Format("{0} {1} {2} Has {3} teeth. tail is {4} cm long", namestr, agestr, genderstr, teethstr, tailstr);
listBox.Items.Add(row);
}
VulpesPosted Feb 8, 2015, 2:38 PM
Song LeePosted Feb 7, 2015, 7:13 PM
I am trying to validate it so it only accepts Double value, not string.
This is the error that I got : "double is a type but is used like a variable"
I also added this:
Double agestr;
agestr = Double.Parse(ageText.Text);
if (Double.Parse(ageText.Text) =! Double) //Getting error here
{
MessageBox.Show("Age must be Double Value");
return;
}
Thank you for the help!
Vikram AgrawalPosted Feb 5, 2015, 10:18 PM
Hi Song Lee,
You should validate your age and teeth textbox so that user will not able to enter any non numeric value in those text boxes
You can write this validation code in TextBox_KeyPress Event
Thank You