943,650 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 3528
  • MS SQL RSS
Aug 1st, 2008
0

Combobox selected value - colored in datagridview

Expand Post »
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


MS SQL Syntax (Toggle Plain Text)
  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] ! ! !
Reputation Points: 10
Solved Threads: 0
Junior Poster
kavithabhaskar is offline Offline
123 posts
since Jun 2008
Aug 15th, 2008
0

Re: Combobox selected value - colored in datagridview

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
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Help Figuring Out Proper Database Schema/Design
Next Thread in MS SQL Forum Timeline: creating pivot table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC