You need to try something like this
int x;
int y;
try
{
int.TryParse(textBox1.Text, out x);
int.TryParse(textBox2.Text, out y);
dataGrid1.Rows.Add(new int[] { x, y });
dataGrid1.Cells[0] = x;
dataGrid1.Cells[1] = y;
}
catch (ArgumentException)
{
MessageBox.Show("One of your text boxes does not contain an integer.");
}
Hope this helps