.NET 4.x DataGridView1 like DataGridView2 - Visual Basic .NET
Формулировка задачи:
Доброе время суток.
Подскажите пожалуйста, как использовать условие отображения информация в DataGridView1 если в DataGridView2 имееются похожие записи?
Решение задачи: «.NET 4.x DataGridView1 like DataGridView2»
textual
Листинг программы
Public Class Form4
Private DT As DataTable
Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
DT = createTable()
DataGridView1.ColumnCount = 2
DataGridView1.RowCount = DT.Rows.Count
For i = 0 To DataGridView1.RowCount - 1
DataGridView1.Rows(i).Cells(0).Value = DT.Rows(i).Item(0)
DataGridView1.Rows(i).Cells(1).Value = DT.Rows(i).Item(1)
Next
DataGridView2.ColumnCount = 1
DataGridView2.RowCount = 20
Dim rnd As New Random
For i = 0 To DataGridView2.RowCount - 1
DataGridView2.Rows(i).Cells(0).Value = rnd.Next(1, 200)
Next
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim vv As Integer
For i = 0 To DataGridView2.RowCount - 1
vv = DataGridView2.Rows(i).Cells(0).Value
For j = 0 To DataGridView1.RowCount - 1
If DataGridView1.Rows(j).Cells(0).Value = vv.ToString Then
DataGridView1.Rows(j).Cells(0).Value = "AD"
DataGridView1.Rows(j).Cells(0).Style.ForeColor = Color.Red
End If
Next
Next
End Sub
Private Function createTable() As DataTable
Dim tb As New DataTable
tb.Columns.Add("ID", System.Type.GetType("System.Int32"))
tb.Columns.Add("tstValue", System.Type.GetType("System.Int32"))
tb.PrimaryKey = {tb.Columns(0)}
Dim rr As DataRow
Dim rnd As New Random
For i = 1 To 50
rr = tb.NewRow
rr.Item(0) = i
rr.Item(1) = rnd.Next(10, 90)
tb.Rows.Add(rr)
Next
Return tb
End Function
End Class