2

我将 Windows 应用程序中的 DataGridView 与 DataTable 绑定。在 DataGridView 的 RowsAdded 事件中,我正在编写代码以更改特定单元格的样式。

我已经尝试过以下代码,但它不起作用

Private Sub grdView_RowsAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles grdView.RowsAdded

        Dim f = New Font("Times New Roman", 10, FontStyle.Bold)
        For index As Integer = e.RowIndex To e.RowIndex + e.RowCount - 1
            Dim row As DataGridViewRow = grdView.Rows(index)
            If Decimal.Parse(row.Cells("Variance Up").Value.ToString) >= Decimal.Parse(txtRise1.Text) Then
                row.Cells("Variance Up").Style.ForeColor = Color.Red
                row.Cells("Variance Up").Style.Font = f
            ElseIf Decimal.Parse(row.Cells("Variance Up").Value.ToString) >= Decimal.Parse(txtRise2.Text) Then
                row.Cells("Variance Up").Style.ForeColor = Color.Red
                row.Cells("Variance Up").Style.Font = f
            End If
        Next
    End Sub

我想要做的如下:

在此处输入图像描述

4