如何将用户输入的数据添加到DataGridView中? [英] How do I add the data a user inputs into a DataGridView?

查看:95
本文介绍了如何将用户输入的数据添加到DataGridView中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridView,它有1列。我希望用户添加他们需要的行数。然后,当他们移动到下一个选项卡时,将保存行。用户输入数据时可以移动到下一个选项卡,如果他们返回,数据仍然存在。但是,当我尝试在离开选项卡时保存数据时,DataGridView的行数为0.因此,不要输入foreach语句,我尝试从中获取单元格数据。



我尝试获取数据时的代码是 -

I have a DataGridView which has 1 column. I want the user to add as many rows they need. Then when they move onto the next tab the rows are saved. At the moment the user enters the data and can move to next tab and if they go back the data is still there. However when I try to save the data when they leave the tab, the row count for the DataGridView is 0. Therefore not entering the foreach statement where I try get the cell data from.

My code for when I try to get the data is-

foreach (DataRow row in gv_mullionList.Rows)
{
  //never gets this far
  //would set cell value to an object
}





为什么我需要做这些行?



Why do I need to do to get the rows?

推荐答案

http://www.c-sharpcorner.com/UploadFile/ANURAGSARKAR19/saving-data-using-datagridview-and-doing-calculations/ [ ^ ]请尝试此链接。当用户进入时他可以在输入后保存数据的所有信息。
http://www.c-sharpcorner.com/UploadFile/ANURAGSARKAR19/saving-data-using-datagridview-and-doing-calculations/[^]Please try this link.Here when user enters all the information he can save the data after doing the entry.


这篇关于如何将用户输入的数据添加到DataGridView中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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