Here's my take on a solution for doing something like this.
For Demo Purpose I build an EbayItem Class :-
public class EbayItem
{
public EbayItem()
{
}
public EbayItem(string sku, int id, string product, int ebayqty, int stockqty)
{
SKU = sku;
ID = id;
ProductName = product;
ebayQty = ebayqty;
stockQty = stockqty;
}
public string SKU { get; set; }
public int ID { get; set; }
public string ProductName { get; set; }
public int ebayQty { get; set; }
public int stockQty { get; set; }
public int difference
{
get { return stockQty - ebayQty; }
set { difference = value; }
}
}
Inside a Windows Form(Form1_Load) I created a few test entries and added them to a List object. The last entry looks to buy 2 grenades, but there's zero in stock :-
List<EbayItem> Inventory = new List<EbayItem>();
Inventory.Add(new EbayItem("SKU1", 1, "Ski-Mask", 1, 10));
Inventory.Add(new EbayItem("SKU2", 2, "Shotgun", 1, 10));
Inventory.Add(new EbayItem("SKU3", 3, "Rounds", 5, 10));
Inventory.Add(new EbayItem("SKU4", 4, "Grenade", 2, 0));
Instead of adding rows manually to my DataGridView, I'm going to create a BindingSource and populate it with my Inventory :-
BindingSource bs = new BindingSource(Inventory, null);
Next, Assign the datasource for my DGV, setting it to the Binding object. This means that any changes made to the list object ripple through to the DGV automatically :-
dataGridView1.DataSource = bs;
All thats left now is to utilise the CellFormatting event handle of the DGV. I use this to highlight any rows where the difference in stocks is zero or less :-
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
int colIndex = e.ColumnIndex;
int rowIndex = e.RowIndex;
if (rowIndex >= 0 && colIndex >= 0)
{
DataGridViewRow theRow = dataGridView1.Rows[rowIndex];
int difference = (int)theRow.Cells[5].Value;
if (difference <= 0)
{
theRow.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
theRow.DefaultCellStyle.ForeColor = System.Drawing.Color.White;
}
}
}
Hope this helps.