简体   繁体   English

确定整数是否是整数列表的成员

[英]Determine if an integer is a member of a list of integers

I need to determine if a particular integer does not exists in a datagridview column. 我需要确定datagridview列中是否存在特定的整数。 I assume I should create an array of the integers from the dgv column, and then compare if the integer exists in the array. 我假设我应该从dgv列创建一个整数数组,然后比较数组中是否存在整数。 However, there is perhaps an easier or simpler way. 但是,也许有一种更简单或更简单的方法。

I have looked at many articles but none of them resolve my task. 我看了很多文章,但没有一个能解决我的问题。 Some of the Stack Overflow articles show similar solutions but I can't quite determine what to do. 一些Stack Overflow文章显示了类似的解决方案,但我无法确定该怎么做。

For a = 0 To Dgv1.RowCount - 1
    If Not Dgv1(1, a).Value = Dgv0(1, m).Value Then
         Dgv0(1, Dgv0.RowCount - 1).Value = Dgv0(1, m).Value
     End If
Next

I hope to compare an integer with a column of integers in a datagridview and if it is present do nothing but if is not present add it to the datagrid view 我希望在datagridview中比较一个整数和一个整数列,如果它存在则什么也不做,但如果不存在则将它添加到datagrid视图

Are you using wpf? 你在用wpf吗? If yes, create a model. 如果是,请创建模型。 provide a checking mechanism at the setter, use observablecollection or list then bind it to the datagirdview 在setter处提供检查机制,使用observablecollection或list然后将其绑定到datagirdview

Get the row and column of the datagridview 获取datagridview

then compare (means condtional statement) to the variable you wanna check 然后比较 (意味着condtional语句)你要检查的变量

and of course it should be inside of loop , loop count is equal to the count of rows you have in the datagridview. 当然它应该在循环内部,循环计数等于datagridview中的行数。

Here's an example code: 这是一个示例代码:

Dim column As String = "YourColumnNameHere"
' Assuming 2 is the number you wanna compare
Dim value As Integer = 2

For row As integer = 0 to dataGridView.RowCount - 1

    If dataGridView.Rows(row).Cells(column).Value = value Then
        ' Do something here
    Else
        ' Do something here
    End If

Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM