Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42220

VS 2010 Error changing indvidual cells in a datagridview

$
0
0
I am trying to change the color of individual cells in a datagridview based on values from the columns. If the CDRGvalue is not blank and the ALOSvalue is greater than the PLOSvalue then I need to change the individual cell back color for the ALOS column (colALOS) and the PLOS column (colPLOS) to red for the patient in that row. Currently, the best I have been able to do is turn the whole line red instead of just the individual cells. Any help, tips, or suggestions are greatly appreciated!

Code:

    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        Dim ALOSValue As Double
        Dim PLOSValue As Double
        Dim CDRGValue As String

        For Each tempRow As System.Windows.Forms.DataGridViewRow In Me.DataGridView1.Rows


            For Each tempCell As Windows.Forms.DataGridViewCell In tempRow.Cells
                ALOSValue = Val(tempRow.Cells.Item("colALOS").Value)
                PLOSValue = Val(tempRow.Cells.Item("colPLOS").Value)
                CDRGValue = tempRow.Cells.Item("colDRG").Value

                If CDRGValue <> "" Then
                    If (ALOSValue > PLOSValue) Then
                        tempCell.Style.BackColor = Color.Red
                    End If
                End If
            Next
        Next
    End Sub


Viewing all articles
Browse latest Browse all 42220

Trending Articles