如何在gridview上检查相同的值? [英] How to check same values on gridview?

查看:77
本文介绍了如何在gridview上检查相同的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果临时gridview上有相同的值,我想在添加gridview之前检查。如果有至少一个相同的值,它将停止读取for循环。



示例:

textbox:4



2

3

4

[4] *剧照增值



在第一列。它会说列表上有相同的数据。

但仍然在4之后输入数据4,因为它与3和2不一样。



 如果 grv_temporary.Rows(i).Cells( 6 )。Text = TextBox1.Text 然后 
msgbox(已有相同的数据 on 列表。
退出
'不要继续处理
Else
'增加值



先谢谢你们。我知道这很简单,但我无法得到它。

解决方案

 boolean found =  false ; 

foreach (DataGridViewRow row in grv_temporary)
{
if (grv_temporary.Rows(i).Cells( 6 )。值== TextBox1.Text)
{
// 存在行
found = true ;
MessageBox.Show( 行已存在);
break ;
}
}

如果(!找到)
{
grv_temporary.Rows。加入(TextBox1.Text); // 您的价值观。
}







试一试。阅读此处 [ ^ ]如果数据已存在,网格视图添加数量.. [ ^ ]


I wanted to check before adding in the gridview if there are same values on the temporary gridview. and if there are atleast one same value it will stop the reading of for loop.

example :
textbox: 4
Column
2
3
4
[4]*stills add the value

in the first column. it will say "There has been same data on the list."
but stills enter the data "4" after 4 because it is not the same with 3 and 2.

If grv_temporary.Rows(i).Cells(6).Text = TextBox1.Text Then
   msgbox(There has been same data on the list.")
Exit For
'do not continue process
Else
'add value


Thanks in advance guys. I know this is simple but i cannot get it.

解决方案

boolean found = false;

foreach (DataGridViewRow row in grv_temporary)
{
    if (grv_temporary.Rows(i).Cells(6).Value == TextBox1.Text)
    {
        // row exists
        found = true;
        MessageBox.Show("Row already exists");
        break;
    }
}

if (!found)
{
    grv_temporary.Rows.Add(TextBox1.Text); // Your values here.
}




Try this. Read here[^] And Grid View add quantity if data already exists..[^]


这篇关于如何在gridview上检查相同的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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