FOLKS:

I fill my data grid view with data and i try to color a few cells based on a condition but nothing seems to work..no errors either..can u pls help me >?

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Final Database.mdb")

con.Open()

Dim cmd As New OleDbCommand

cmd = New OleDbCommand("SELECT * from table2", con)

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Try

Dim ds As DataSet = New DataSet()

da.Fill(ds, "table2")

DataGridView1.DataSource = ds.Tables("table2").DefaultView

For Each r As DataGridViewRow In DataGridView1.Rows

If r.IsNewRow = False AndAlso Not TypeOf (r.Cells("MFG").Value) Is DBNull Then

Select Case r.Cells("MFG").Value.ToString.ToUpper

Case "DELL", "HP"

r.Cells("MFG").Style.BackColor = Color.Green

End Select

End If

Next

Finally

con.Close()

cmd = Nothing

da.Dispose()

con.Dispose()

End Try

con.Close()

cmd = Nothing

con.Dispose()

End Sub

hi:

how do i get an else condition here? does it have to be a case format again ?

say if it was not DELL or HP and it was compaq.. i want to make it appear red..

pls assist..

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim con As OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Final Database.mdb")

con.Open()

Dim cmd As New OleDbCommand

cmd = New OleDbCommand("SELECT * from table2", con)

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Try



Dim ds As DataSet = New DataSet()

da.Fill(ds, "table2")

DataGridView1.DataSource = ds.Tables("table2").DefaultView

Finally



con.Close()

cmd = Nothing



da.Dispose()

con.Dispose()

End Try



For Each r As DataGridViewRow In DataGridView1.Rows

If r.IsNewRow = False AndAlso Not TypeOf (r.Cells("MFG").Value) Is DBNull Then



Select Case r.Cells("MFG").Value.ToString.ToUpper

Case "DELL", "HP"



r.Cells("MFG").Style.ForeColor = Color.Green

End Select



End If



Next



con.Close()

cmd = Nothing



con.Dispose()

End Sub



Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

End



End Sub
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.