0

Hi I have 4 comboboxes..and any value that I choose.. I get a whole set of fields displayed in my datagrid view..

I want to make a difference..the value that I choose in the combobox, has to appear green in color in my datagridview. How do I do this ? I am not sure what property i have to use.. my code is as follows.. I dont want to use a T-SQL to display only limited records.. I want colored records in the datagridview..! please assist

Imports System.Windows.forms

Imports System.Data.oledb




Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim objcmd As New Data.OleDb.OleDbCommand

Dim objrdr As Data.OleDb.OleDbDataReader

Dim TableName As String = ""

Dim query As String = ""

Dim cbo As ComboBox = Nothing

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

con.Open()

For x As Int32 = 1 To 5

Select Case x

Case 1

query = "SELECT DISTINCT Mfg FROM table1 WHERE Mfg IS NOT NULL ORDER BY Mfg"

TableName = "Mfg"

cbo = ComboBox1

Case 2

query = "SELECT DISTINCT MAKE FROM table1 WHERE MAKE IS NOT NULL ORDER BY MAKE"

TableName = "Make"

cbo = ComboBox2

Case 3

query = "SELECT DISTINCT GRAPHICSCARD FROM table1 WHERE GRAPHICSCARD IS NOT NULL ORDER BY GRAPHICSCARD"

TableName = "GRAPHICSCARD"

cbo = ComboBox3

Case 4

query = "SELECT DISTINCT GRAPHICSVERSION FROM table1 WHERE GRAPHICSVERSION IS NOT NULL ORDER BY GRAPHICSVERSION"

TableName = "GRAPHICSVERSION"

cbo = ComboBox4

End Select

objcmd.Connection = con

objcmd.CommandText = query

objrdr = objcmd.ExecuteReader

cbo.Items.Clear()

If objrdr.HasRows Then

Do While objrdr.Read

cbo.Items.Add(objrdr.GetValue(0))

Loop

End If

objrdr.Close()

Next

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

End

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.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")

Dim cmd As New OleDbCommand

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

con.Open()

Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd)

Try

Dim ds As DataSet = New DataSet()

ds.Tables.Add("table2")

da.Fill(ds, "table2")

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

datagridview1.

Finally

con.Close()

cmd = Nothing

da.Dispose()

con.Dispose()

End Try

End Sub

End Class
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by kb.net
0

Hi,

My friend, your question have nothing to do with MSSQL, you should have posted it in Vb.net forum and i think you will need to use Cellstye.forecolor=Color.green

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.