I'm trying to programatically build a DataGrid from 2 different sources of data. I have a List and a DataGrid. The problem isn't with my data processing, It's to do with the values of the DataGridViewRow object. Here is my code:
protected void buildGrid()
{
dgResults.Columns.Add( "sku", "SKU" );
dgResults.Columns.Add( "itemID", "Item ID" );
dgResults.Columns.Add( "productName", "Product Name" );
dgResults.Columns.Add( "eBayQty", "eBay Qty" );
dgResults.Columns.Add( "stockQty", "Stock Qty" );
dgResults.Columns.Add( "difference", "Difference" );
//Add the eBayItem data to the table
foreach ( string[] eBayItem in ebayItems )
{
string SKU = eBayItem[1].ToString();
int eBayQty = Convert.ToInt32(eBayItem[2]);
string ProductName = "";
int stockQty = 0;
int qtyDifference = 0;
DataRow[] rows = dbData.Select( "sku ='" + SKU + "'" );
if (rows.Length == 1) {
stockQty = Convert.ToInt32( rows[0]["quantity"] );
ProductName = rows[0]["ProductName"].ToString();
}
qtyDifference = stockQty - eBayQty;
DataGridViewRow dgvr = new DataGridViewRow();
dgvr.SetValues( SKU, eBayItem[0].ToString(), ProductName, eBayQty, stockQty, qtyDifference );
if ( qtyDifference != 0 || eBayQty > stockQty )
{
dgvr.DefaultCellStyle.BackColor = System.Drawing.Color.Red;
dgvr.DefaultCellStyle.ForeColor = System.Drawing.Color.White;
}
else if ( stockQty > eBayQty )
dgvr.DefaultCellStyle.BackColor = System.Drawing.Color.LightGoldenrodYellow;
else
dgvr.DefaultCellStyle.BackColor = System.Drawing.Color.GreenYellow;
dgResults.Rows.Add(dgvr);
}
}
The rows are adding to the DataGrid and they are being colored appropriately, but each cell within the rows contain no data? All I end up with is several blank rows that have their background properties set.
Any one got any ideas?
Thanks in advance.