i have this code and it kinda works but not properly.

i need it to look at the coloum in a datagrid and make the back colour red if over 1.6(in sql this field is saved as Varchar(10))

but at the min, i have a value of 1.5 and it is making the back colour red

Dim cell As DataGridViewCell
        Dim CellVar As Integer
        For Each row As DataGridViewRow In Me.OEEGrid.Rows
            cell = row.Cells("CD")
            CellVar = CInt(row.Cells("CD").Value)
            If CellVar >= 1.6 Then
                '  cell.Style.ForeColor = Color.Red
                cell.Style.BackColor = Color.Red
            Else
                cell.Style.ForeColor = Color.Black
            End If

Recommended Answers

All 3 Replies

Member Avatar for Unhnd_Exception

Use a double. Integers are whole numbers.

Change CellVar to Double and cast with cDbl(row.cell...

i have this code and it kinda works but not properly.

i need it to look at the coloum in a datagrid and make the back colour red if over 1.6(in sql this field is saved as Varchar(10))

but at the min, i have a value of 1.5 and it is making the back colour red

Dim cell As DataGridViewCell
        Dim CellVar As Integer
        For Each row As DataGridViewRow In Me.OEEGrid.Rows
            cell = row.Cells("CD")
            CellVar = CInt(row.Cells("CD").Value)
            If CellVar >= 1.6 Then
                '  cell.Style.ForeColor = Color.Red
                cell.Style.BackColor = Color.Red
            Else
                cell.Style.ForeColor = Color.Black
            End If

How would you handle a DBNULL value in the field of the datagridview?

I've attempted ot put an IF statement to catch the null value, but I get errors when I try that..

Dim cell As DataGridViewCell
        Dim cellVar As Integer
        For Each row As DataGridViewRow In Me.TblArrestDataGridView.Rows
            cell = row.Cells(6)
            cellVar = CInt(row.Cells(6).Value)
            If cellVar = DBNull Then
                cellVar = 0
            End If
            If cellVar >= 200 Then
                cell.Style.BackColor = Color.Red
            End If
        Next
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.