Combobox selected value - colored in datagridview

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 117
Reputation: kavithabhaskar is an unknown quantity at this point 
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Combobox selected value - colored in datagridview

 
0
  #1
Aug 1st, 2008
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


  1. Imports System.Windows.forms
  2.  
  3. Imports System.DATA.oledb
  4.  
  5.  
  6.  
  7.  
  8. Public Class Form1
  9.  
  10. Private Sub Form1_Load(ByVal sender AS System.Object, ByVal e AS System.EventArgs) Handles MyBase.LOAD
  11.  
  12. Dim objcmd AS New DATA.OleDb.OleDbCommand
  13.  
  14. Dim objrdr AS DATA.OleDb.OleDbDataReader
  15.  
  16. Dim TableName AS String = ""
  17.  
  18. Dim query AS String = ""
  19.  
  20. Dim cbo AS ComboBox = Nothing
  21.  
  22. Dim con AS New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Final Database.mdb")
  23.  
  24. con.Open()
  25.  
  26. FOR x AS Int32 = 1 TO 5
  27.  
  28. SELECT Case x
  29.  
  30. Case 1
  31.  
  32. query = "SELECT DISTINCT Mfg FROM table1 WHERE Mfg IS NOT NULL ORDER BY Mfg"
  33.  
  34. TableName = "Mfg"
  35.  
  36. cbo = ComboBox1
  37.  
  38. Case 2
  39.  
  40. query = "SELECT DISTINCT MAKE FROM table1 WHERE MAKE IS NOT NULL ORDER BY MAKE"
  41.  
  42. TableName = "Make"
  43.  
  44. cbo = ComboBox2
  45.  
  46. Case 3
  47.  
  48. query = "SELECT DISTINCT GRAPHICSCARD FROM table1 WHERE GRAPHICSCARD IS NOT NULL ORDER BY GRAPHICSCARD"
  49.  
  50. TableName = "GRAPHICSCARD"
  51.  
  52. cbo = ComboBox3
  53.  
  54. Case 4
  55.  
  56. query = "SELECT DISTINCT GRAPHICSVERSION FROM table1 WHERE GRAPHICSVERSION IS NOT NULL ORDER BY GRAPHICSVERSION"
  57.  
  58. TableName = "GRAPHICSVERSION"
  59.  
  60. cbo = ComboBox4
  61.  
  62. End SELECT
  63.  
  64. objcmd.Connection = con
  65.  
  66. objcmd.CommandText = query
  67.  
  68. objrdr = objcmd.ExecuteReader
  69.  
  70. cbo.Items.Clear()
  71.  
  72. IF objrdr.HasRows Then
  73.  
  74. Do While objrdr.READ
  75.  
  76. cbo.Items.ADD(objrdr.GetValue(0))
  77.  
  78. Loop
  79.  
  80. End IF
  81.  
  82. objrdr.Close()
  83.  
  84. Next
  85.  
  86. End Sub
  87.  
  88. Private Sub Button5_Click(ByVal sender AS System.Object, ByVal e AS System.EventArgs) Handles Button5.Click
  89.  
  90. End
  91.  
  92. End Sub
  93.  
  94. Private Sub Button3_Click(ByVal sender AS System.Object, ByVal e AS System.EventArgs) Handles Button3.Click
  95.  
  96. Dim con AS OleDbConnection = New OleDb.OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=C:\Documents and Settings\bashkark\Desktop\Final Database.mdb")
  97.  
  98. Dim cmd AS New OleDbCommand
  99.  
  100. cmd = New OleDbCommand("Select * from table2 ", con)
  101.  
  102. con.Open()
  103.  
  104. Dim da AS OleDbDataAdapter = New OleDbDataAdapter(cmd)
  105.  
  106. Try
  107.  
  108. Dim ds AS DataSet = New DataSet()
  109.  
  110. ds.TABLES.ADD("table2")
  111.  
  112. da.Fill(ds, "table2")
  113.  
  114. DataGridView1.DataSource = ds.TABLES("table2").DefaultView
  115.  
  116. datagridview1.
  117.  
  118. Finally
  119.  
  120. con.Close()
  121.  
  122. cmd = Nothing
  123.  
  124. da.Dispose()
  125.  
  126. con.Dispose()
  127.  
  128. End Try
  129.  
  130. End Sub
  131.  
  132. End Class
Last edited by peter_budo; Aug 1st, 2008 at 12:39 pm. Reason: Use [code] tags not [quote] ! ! !
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: Combobox selected value - colored in datagridview

 
0
  #2
Aug 15th, 2008
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
It is never about the number of languages you know, you either have the logic of programming or you don't ...

Some of the codes I post are collected from different sites during the past couple of years, so I would like to thank them for their help and for enabling me to help.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC