将行以编程方式添加到无界的datagridview中 [英] adding rows programatically to an unbounded datagridview

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

问题描述

将值从一个表单发送到另一个表单,然后要显示在dgv中,

i m sending values from one form to another form, then want to display in dgv,

im尝试此操作,执行过程中没有错误,bt它不在dgv ..中显示数据
plz hepl me

i m trying this, there is no error during execution, bt it does not show data in dgv.. plz hepl me

        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天全站免登陆