Что ж, вы можете заставить DGV установить для вас значения четвертого столбца, обработав событие DataGridView.CellFormatting , поэтому вам не нужно делать это вручную, нажав эту кнопку.
Предполагая, что индексы столбцов Length
, Width
и Height
равны 0, 1, 2
соответственно, и нам нужно установить значения индекса 3
.
'...
'Declare variables for the max values allowed...
Private ReadOnly MaxLength As Integer = 600
Private ReadOnly MaxWidth As Integer = 400
Private ReadOnly MaxHeight As Integer = 600
'...
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
Dim s = DirectCast(sender, DataGridView)
Dim length, width, height As Integer
If e.RowIndex > -1 AndAlso
Not Enumerable.Range(0, 2).Any(Function(i) s(i, e.RowIndex).Value Is Nothing) AndAlso
Integer.TryParse(s(0, e.RowIndex).Value.ToString, length) AndAlso
Integer.TryParse(s(1, e.RowIndex).Value.ToString, width) AndAlso
Integer.TryParse(s(2, e.RowIndex).Value.ToString, height) Then
s(3, e.RowIndex).Value = If(length <= MaxLength AndAlso width <= MaxWidth AndAlso height <= MaxHeight,
"Suitable", "Unsuitable")
End If
End Sub
Это все это.
Однако, и по любым неизвестным причинам вам нужно сделать это вручную нажатием кнопки, затем вам нужно обработать событие Click
следующим образом:
Dim dgv = DataGridView1
Dim length, width, height As Integer
For Each r In dgv.Rows.Cast(Of DataGridViewRow).
Where(Function(x) Not Enumerable.Range(0, 2).Any(Function(i) x.Cells(i).Value Is Nothing))
If Integer.TryParse(r.Cells(0).Value.ToString, length) AndAlso
Integer.TryParse(r.Cells(1).Value.ToString, width) AndAlso
Integer.TryParse(r.Cells(2).Value.ToString, height) Then
r.Cells(3).Value = If(length <= MaxLength AndAlso width <= MaxWidth AndAlso height <= MaxHeight,
"Suitable", "Unsuitable")
End If
Next