如何在datagrid视图中添加新行 [英] How can I add new row in datagrid view

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

问题描述

如果已有很多行,我必须添加更多新行&该行包含我在文本框中写入的数据。然后如何在数据网格中继续添加另一行的行。



我尝试过:



gridView.Rows.Add(value)。使用它,它显示行但清除旧行。我必须附加新行。但这不起作用。

If there is already to many rows and i have to add more new row & that row contain the data which i have write in textbox. Then how to add that rows with another rows in continue in data grid.

What I have tried:

gridView.Rows.Add(value). Using this it display the row but clear the old rows. I have to append the new rows. But this is not working.

推荐答案

有一个很好的例子:

DataGridView.DataSource属性(System.Windows.Forms) [ ^ ]



您基本上需要设置GridView的数据源属性。



有一个完整的例子那里,但基本是:



There's a good example at:
DataGridView.DataSource Property (System.Windows.Forms)[^]

You basically need to set your datasource property of your GridView.

There's a complete example there, but the basics are:

bindingSource1.DataSource = GetData("Select * From Products");
 dataGridView1.DataSource = bindingSource1;


Quote:

gridView.Rows.Add(值)。使用它,它显示行但清除旧行。我必须附加新行。但这不起作用。

gridView.Rows.Add(value). Using this it display the row but clear the old rows. I have to append the new rows. But this is not working.



这不是真的! 添加方法(System.Windows.Forms) [ ^ ]将新行添加到 DataGridViewRowCollection 。这不会重置以前的集合。



如果您想将数据绑定到DataGridView,请按照以下步骤操作:

如何:将数据绑定到Windows窗体DataGridView控件| Microsoft Docs [ ^ ]

如何:将对象绑定到Windows窗体DataGridView控件| Microsoft Docs [ ^ ]


It's not true! Add Method (System.Windows.Forms)[^] adds new row to the DataGridViewRowCollection. This does not reset previous collection.

If you would like to bind data to DataGridView, please, follow these:
How to: Bind Data to the Windows Forms DataGridView Control | Microsoft Docs[^]
How to: Bind Objects to Windows Forms DataGridView Controls | Microsoft Docs[^]


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

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