以编程方式向无边界datagridview添加行 [英] adding rows programmatically to an unbounded datagridview

查看:58
本文介绍了以编程方式向无边界datagridview添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将值从一种形式发送到另一种形式,然后要显示在dgv中,

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..

lineItemsDGV.Rows.Add();

int RowIndex = lineItemsDGV.RowCount - 1;
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;


推荐答案

您已经关闭。

您可以做的是使用对 DataGridViewRowCollection.Rows.Add()方法,它是刚刚添加的行的索引值。

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.

将代码更改为此:

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;

这篇关于以编程方式向无边界datagridview添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆