I wrote a test following you're description and all cells colored correctly.
There's more info at
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcell.aspx[
^]
public partial class Form1 : Form
{
private Random rnd;
private int nSize = 4;
public Form1()
{
InitializeComponent();
rnd = new Random();
for (int c = 0; c < nSize; c++)
{
this.dataGridView1.Columns.Add("Col" + c.ToString(), "Col" + c.ToString());
}
}
private void buttonImport_Click(object sender, EventArgs e)
{
this.dataGridView1.Rows.Clear();
int n = this.dataGridView1.Columns.Count;
string[] nums;
for (int r = 0; r < nSize; r++)
{
nums = new string[n];
for (int c = 0; c < n; c++)
{
nums[c] = (rnd.Next(-10, 10)).ToString();
}
this.dataGridView1.Rows.Add(nums);
}
ColorCells();
}
private void ColorCells()
{
int n = this.dataGridView1.Columns.Count;
for (int r = 0; r < nSize; r++)
{
for (int c = 0; c < n; c++)
{
string val = (string) this.dataGridView1.Rows[r].Cells[c].Value;
int v;
if(Int32.TryParse(val, out v) == false) continue;
if(v<0)
this.dataGridView1.Rows[r].Cells[c].Style.BackColor = Color.Red;
else
this.dataGridView1.Rows[r].Cells[c].Style.BackColor = Color.White;
}
}
}
}