adding rows programmatically to an unbounded datagridview

前端 未结 3 1578
眼角桃花
眼角桃花 2021-01-29 04:01

I\'m sending values from one form to another form, then want to display in dgv,

I\'m trying this, there is no error during execution, bt it does not show data in dgv..

3条回答
  •  旧巷少年郎
    2021-01-29 04:35

    You're close.

    What you can do is use the return value of your call to DataGridViewRowCollection.Rows.Add() method, which is the index value of the just added row.

    Change your code to this:

    int RowIndex = lineItemsDGV.Rows.Add();
    DataGridViewRow NewRow = lineItemsDGV.Rows[RowIndex];
    NewRow.Cells[0].Value = item.Product_id;
    NewRow.Cells[1].Value = item.product_name;
    NewRow.Cells[2].Value = item.specification;
    NewRow.Cells[3].Value = item.unit_price;
    NewRow.Cells[4].Value = item.unit_price * 1;
    

提交回复
热议问题