Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding rows to datagridview with existing columns

Tags:

I have a DataGridView with several created columns. I've add some rows and they get displayed correctly; however, when I click on a cell, the content disappears.

What am I doing wrong?

The code is as follows:

foreach (SaleItem item in this.Invoice.SaleItems)
{
    DataGridViewRow row = new DataGridViewRow();
    gridViewParts.Rows.Add(row);

    DataGridViewCell cellQuantity = new DataGridViewTextBoxCell();
    cellQuantity.Value = item.Quantity;
    row.Cells["colQuantity"] = cellQuantity;

    DataGridViewCell cellDescription = new DataGridViewTextBoxCell();
    cellDescription.Value = item.Part.Description;
    row.Cells["colDescription"] = cellDescription;

    DataGridViewCell cellCost = new DataGridViewTextBoxCell();
    cellCost.Value = item.Price;
    row.Cells["colUnitCost1"] = cellCost;

    DataGridViewCell cellTotal = new DataGridViewTextBoxCell();
    cellTotal.Value = item.Quantity * item.Price;
    row.Cells["colTotal"] = cellTotal;

    DataGridViewCell cellPartNumber = new DataGridViewTextBoxCell();
    cellPartNumber.Value = item.Part.Number;
    row.Cells["colPartNumber"] = cellPartNumber;
}

Thanks!