i want to use this code at datagridview for cell 1,2 only
double vmv = 8; double vbv = 6;
if (string.IsNullOrWhiteSpace(textBox1.Text)) // to avoid error when textbox empty
{
MessageBox.Show("Please Enter Number");
}
else
{
if (Convert.ToDouble(textBox1.Text) >= vmv )
{
textBox1.BackColor = Color.Red;
}
else if (Convert.ToDouble(textBox1.Text) <= vbv)
{
textBox1.BackColor = Color.Blue;
}
else
{
textBox1.BackColor = Color.White;
}
}
so i try this one but didnt work
double vmv = 8; // convert to double to avoid error compare string to string double vbv = 6;
if (Convert.ToDouble(dataGridView1.SelectedCells[2].Value) >= vmv )
{
dataGridView1.SelectedCells[2].Style.BackColor = Color.Red;
}
else if (Convert.ToDouble(dataGridView1.SelectedCells[2].Value) <= vbv)
{
dataGridView1.SelectedCells[2].Style.BackColor = Color.Blue;
}
it show me error "Index was out of range. Must be non-negative and less than the size of the collection."