如何检查所有列是否已填充 [英] how to check that all columns are filled

查看:88
本文介绍了如何检查所有列是否已填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在winForm上有一个gridview和一个按钮。我想将数据从datagrid保存到表,但我想确保用户已填充gv的所有列。如何在按钮单击事件上检查它?

解决方案

您好,我认为更好的方法是检查用户是否在开始时正确填充了数据。



要检查datagridview是否包含有效数据,您可以使用以下内容:





  foreach (DataGridViewRow row  in  dataGridView1.Rows) 
{
if (row.Cells [ 1 ]。Value.toString( ))== // 取决于未填充的单元格//逻辑
{

// 单元格为空,您可以在c中ase检查值是否为空

}
}





我是完全反对使用这种解决方案。最好的方法是创建一个类,然后将类影响到数据网格。

然后你将只使用列表。更简单,更快捷,更高效。



  //  你必须迭代抛出列表中的元素。 
Foreach(用户用户 in userList)
{
if (user.Name == null || user.Name ==
{
// 用户名未填写
}
}

希望您考虑使用第二种解决方案。







希望它帮助


i have a gridview and a button on winForm. i want to save data from datagrid to a table but i want to ensure that user have filled all columns of gv. how can i check it on button click event??

解决方案

Hi, i think a better apporch is to check that the user have filled the data correctly in the begining.

To check if the datagridview contains valid data you may use somthing like this:


foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    if (row.Cells[1].Value.toString()) == "") //depends on your not filled cell                                                           //logic 
                    {

//the cell is empty, you may in your case check if the value is null
                        
                    }
                }



I am totaly against using this kind of solution. the best way is to create a class and then affect the class to the datagrid.
your will then work only with lists. much easier, faster and efficient.

//you will have to iterate throw the elements of your list.
Foreach(User user in userList)
{
if(user.Name == null || user.Name == "")
   {
      //the user Name is not filled
   }
}

Hope you will consider using the second solution.




Hope it helps.


这篇关于如何检查所有列是否已填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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