Find Missing Number in a natural sequence of numbers , DGV's Cells

  • Thread starter Thread starter Kevin993
  • Start date Start date
K

Kevin993

Guest
Greetings,

As you can see in the picture bellow, I have a DGV with some cells and each cell containts an integer number.

1538680.jpg

if you sort all the numbers above, you see that numbers are from 1 to 31, BUT some numbers are missing in between, like 2 and 3 (instead of 2 and 3 there are 23 and 24).

I need to loop through each cell of my DGV and check if the number in the current cell is the one that is missing , if it is missing I show a Msgbox, for example. So looping throught the DGV is like

For r As Integer = 0 To dgv.Rows.Count - 1


For c As Integer = 0 To dgv.ColumnCount - 1

[Operation]

Next


Next


I know the Starting number and the Ending number (with are 1 and 31 in the above example), So I thought of a function that can generate my natural number List:


Public nList As New List(Of Integer)

Public Function Generate_Number_nList(ByVal Start_NO As Integer, ByVal End_NO As Integer) As List(Of Integer)


For x As Integer = Start_NO To End_NO
nlist.Add(x)

Next


Return nList


End Function


Then my idea was to compare the current cell's number with the list of integer. If it is found then it is not missing. But then I found out that it doesn't find any missing and it shouldn't rationally. Because if for example, current cell value is 1 then it surly exists in the list. if it is 23, it also exists in the list. I can not find the missing number in the sequence this way, Right ?


Any Suggestion ? Thanks in advance.

Continue reading...
 
Back
Top