繁体   English   中英

比较Datagridviews vb.net

[英]Comparing Datagridviews vb.net

我有两个datagridviews都显示数据(每个显示一个组-1和2),基本上它们两个都显示零件和插槽号,还有一些其他位,零件号和插槽是主要信息,第一个gridview显示当前零件和他们去的插槽号,第二个gridview显示了他们要继续前进的下一组(零件号和插槽)。 组之间有共同点,例如在第一和第二个Gridview中显示了插槽1中的示例1111-1111-我需要尝试做的是将相似行的第二个Gridview背景着色为绿色(如果它存在于第一个,但如果不存在,则将行涂成红色。

我已经显示了所有正确的数据,只需要将相似性涂成绿色,将第二个Gridview中丢失的相似性涂上第一组红色。

我已经尝试过谷歌,但什么都没有真正工作,我希望你们一个女孩可以帮助。

以下是用于填充datagridviews的大多数代码。

    connect()

    If combo_line.Text = "All" Then
        cmd.CommandText = "SELECT v_machine, v_part, v_feedertype, v_slot, v_track FROM [sql_valor_groups] ORDER BY v_machine ASC"
    Else
        If combo_machine.Text = "All" Then
            cmd.CommandText = "SELECT v_machine, v_part, v_feedertype, v_slot, v_track FROM [sql_valor_groups] WHERE v_line = '" & combo_line.Text & "' AND v_group = '" & combo_group.Text & "' ORDER BY v_machine ASC"
            cmd2.CommandText = "SELECT v_machine, v_part, v_feedertype, v_slot, v_track FROM [sql_valor_groups] WHERE v_line = '" & combo_line.Text & "' AND v_group = '" & combo_group2.Text & "' ORDER BY v_machine ASC"
        Else
            cmd.CommandText = "SELECT v_machine, v_part, v_feedertype, v_slot, v_track FROM [sql_valor_groups] WHERE v_line = '" & combo_line.Text & "' AND v_machine = '" & combo_machine.Text & "' AND v_group = '" & combo_group.Text & "' ORDER BY v_machine ASC"
            cmd2.CommandText = "SELECT v_machine, v_part, v_feedertype, v_slot, v_track FROM [sql_valor_groups] WHERE v_line = '" & combo_line.Text & "' AND v_machine = '" & combo_machine.Text & "' AND v_group = '" & combo_group2.Text & "' ORDER BY v_machine ASC"
        End If

    End If


    Dim dataAdapter = New SqlDataAdapter(cmd.CommandText, con.ConnectionString)
    Dim table As New DataTable()
    table.Locale = System.Globalization.CultureInfo.InvariantCulture
    dataAdapter.Fill(table)
    Me.BindingSource.DataSource = table

    DataGridView.DataSource = BindingSource

    DataGridView.Columns(0).HeaderText = "Machine:"
    DataGridView.Columns(1).HeaderText = "Part:"
    DataGridView.Columns(2).HeaderText = "Feeder Type:"
    DataGridView.Columns(3).HeaderText = "Slot:"
    DataGridView.Columns(4).HeaderText = "Track:"

    DataGridView.EnableHeadersVisualStyles = False

    DataGridView.RowTemplate.MinimumHeight = 30



    Dim dataAdapter2 = New SqlDataAdapter(cmd2.CommandText, con2.ConnectionString)
    Dim table2 As New DataTable()
    table2.Locale = System.Globalization.CultureInfo.InvariantCulture
    dataAdapter2.Fill(table2)
    Me.BindingSource2.DataSource = table2

    DataGridView2.DataSource = BindingSource2

    DataGridView2.Columns(0).HeaderText = "Machine:"
    DataGridView2.Columns(1).HeaderText = "Part:"
    DataGridView2.Columns(2).HeaderText = "Feeder Type:"
    DataGridView2.Columns(3).HeaderText = "Slot:"
    DataGridView2.Columns(4).HeaderText = "Track:"

    DataGridView2.EnableHeadersVisualStyles = False

    DataGridView2.RowTemplate.MinimumHeight = 30

    disconnect()

从datagridview迭代行并在datagridview2中进行匹配

    For i As Integer = 0 To DataGridView.Rows.Count() - 1 Step +1
        Dim row As DataGridViewRow = DataGridView.Rows(i)
        If DataGridView2.Rows.Count() > 0 Then
            For j As Integer = 0 To DataGridView2.Rows.Count() - 1 Step +1
                If row.Cells(1).Value.ToString() = DataGridView2.Rows(j).Cells(1).Value.ToString() And row.Cells(3).Value.ToString() = DataGridView2.Rows(j).Cells(3).Value.ToString() Then
                    DataGridView2.Rows(i).DefaultCellStyle.BackColor = Color.Green
                Else
                    DataGridView2.Rows(i).DefaultCellStyle.BackColor = Color.Red
                End If
            Next
        End If
    Next

暂无
暂无

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

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