datagridviewrow添加行 [英] datagridviewrow adding row

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

问题描述

你好

我在向未绑定的datagridview添加空行时遇到了一些问题。



我有这个代码,我首先克隆列从我需要的另一个dgv(dg)到dgv(dgadd),然后我添加了行,但是我得到了多个列

  foreach (DataGridViewColumn c  in  dg.Columns)
{
dgadd.Columns.Add(c.Clone()< span class =code-keyword> as DataGridViewColumn);

}
dgadd.Rows.Add();





这就是dg我有5列但是当我运行这个代码时

在dgadd而不是5列我得到15个,那5列乘以两次我不知道为什么

解决方案

看看这里: DataGridViewRow Class [ ^ ] 。要向DataGridView添加新的空白行,请使用以下内容:

 DataGridViewRow dgvr =  new  DataGridViewRow; 
// 添加列
DataGridView1.Rows.Add(dgvr);





注意:您需要根据现有列添加列。



更多:

DataGridView.Rows Property [ ^


Hello
I have a slight problem with adding blank row to unbound datagridview.

I have this code where I first clone columns from another dgv (dg) to dgv(dgadd) that I need, and then I add row, but I get multiple columns

foreach (DataGridViewColumn c in dg.Columns)
            {
                dgadd.Columns.Add(c.Clone() as DataGridViewColumn);

            }
            dgadd.Rows.Add();



here's the thing, in dg I have 5 columns but when I run this code
in dgadd instead of 5 columns I get 15 of them, those 5 columns multiply twice and I dont know why

解决方案

Have a look here: DataGridViewRow Class[^]. To add new blank row to DataGridView, use something like that:

DataGridViewRow dgvr = new DataGridViewRow;
//add columns
DataGridView1.Rows.Add(dgvr);



Note: you need to add columns based on existing columns.

More:
DataGridView.Rows Property[^]


这篇关于datagridviewrow添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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