| | |
Changing color of cell in datagridview based on a condition.. CODE not working
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
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 >?
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 >?
VB.NET Syntax (Toggle Plain Text)
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
•
•
Join Date: Jun 2008
Posts: 117
Reputation:
Solved Threads: 0
Re: Changing color of cell in datagridview based on a condition.. CODE not working
0
#2 Aug 6th, 2008
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..
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..
VB.NET Syntax (Toggle Plain Text)
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
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
Re: Changing color of cell in datagridview based on a condition.. CODE not working
0
#3 Aug 8th, 2008
Look here for an example solution to your problem:
http://www.vb-tips.com/dbpages.aspx?...5-cf57ce269df2
http://www.vb-tips.com/dbpages.aspx?...5-cf57ce269df2
![]() |
Other Threads in the VB.NET Forum
- Previous Thread: Simple file transfer using Serial Ports in VB2005
- Next Thread: How to use fieldname in 'if' condition ?
| Thread Tools | Search this Thread |
.net .net2008 30minutes 2005 2008 access account arithmetic array basic bing button buttons center check code combobox component connectionstring crystalreport data database databasesearch datagrid datagridview date design dissertation dissertations dropdownlist excel fade file-dialog filter folder ftp generatetags google gridview hardcopy images input insert intel internet mobile monitor ms net networking objects output panel passingparameters peertopeervideostreaming picturebox picturebox1 port position print printing problem problemwithinstallation project save searchbox searchvb.net select serial shutdown soap survey table tcp temperature text textbox timer timespan toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





