How to organize a search of cells in the range, or rather in a single column, searching a particular record in Visual Basic?

It is necessary to organize search of cells in only one column to search specific record:
Dim new_PriemRow As MEDHOUSEDataSet.PriemRow
'Flag to distinguish the first occurrence from the subsequent'
Dim firstMatch As Boolean = True
'Through all lines'
For Each row As DataGridViewRow In DataGridView1.Rows
 'Loop through all the cells'
 For Each cell As DataGridViewCell In row.Cells
 'If the formatted value of the cell contains the text'
 If cell.FormattedValue.ToString().Contains(ComboBox4.Text) Then
 If (firstMatch) Then
 'If there is a match'
 cell.Style.ForeColor = Color.Red
 MsgBox("Record could not be added, because this time is already occupied!", MsgBoxStyle.OkOnly)
 Exit Sub
 End If
 firstMatch = False
 End If

You need to add?
July 9th 19 at 10:04
1 answer
July 9th 19 at 10:06
A simple search of cells in the right column of the DataGridView like this:
'Index column'
For Each Row As DataGridViewRow In DataGridView1.Rows

'By column name'
For Each Row As DataGridViewRow In DataGridView1.Rows

If a range of rows in a particular column, then:
'Range of cells'
Dim RowStart = 3,
 RowEnd = 5,
 ColumnIndex = 1 'the column Index, starting from 0. Either the column name'

'Display cell values of the 2nd column of rows 3 and 5'
For i = RowStart - 1 To RowEnd - 1

Record search:
Dim str = "Blah-blah-blah"
For Each Row As DataGridViewRow In DataGridView1.Rows
 If Row.Cells(0).Value = str Then
 MsgBox(String.Format (Value, "{0}"" already exists!", str))
 End If

Find more questions by tags Visual BasicVisual Studio