在VB.net中如何根据不同的条件为dataGridView中的不同行着色

时间:2016-08-06 17:35:06

标签: vb.net

我的代码是这样的: 我只是一个bignner,我无法让这个代码为我工作。请帮助我

Private Sub dgvOrdersData_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvOrdersData.CellFormatting
    If e.RowIndex <> dgvOrdersData.NewRowIndex Then
        If e.ColumnIndex = dgvOrdersData.Columns("CashOrCredit").Index Then
            If e.Value.ToString = "Credit" Then
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Yellow
            Else
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Nothing
            End If
        End If

    If e.ColumnIndex = dgvOrdersData.Columns("Job").Index Then
            If e.Value.ToString = "PendingJob" Then
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
            Else
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Nothing
            End If
        End If

    If e.ColumnIndex = dgvOrdersData.Columns("Job").Index AND e.ColumnIndex = dgvOrdersData.Columns("CashOrCredit").Index Then
            If e.Value.ToString = "PendingJob & Credit " Then
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Pink
            Else
                dgvOrdersData.Rows(e.RowIndex).DefaultCellStyle.BackColor = Nothing
            End If
        End If


    End If
End Sub

0 个答案:

没有答案