Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional formatting and between values 2

Status
Not open for further replies.

JPimp

Technical User
Mar 27, 2007
79
0
0
US
This is a really dumb question, and I know there is an easy solution, but either I am too tired or too dumb to see it...

I want to check for values and color code cells in my Datagrid based on the value, this works great for my red, but when I do yellow, it colors all cells yellow because I am not establishing my parameters correct...

Code:
'Conditional Formatting for Out of Spec - Length Top XD (Red):

            If Not LengthTopXD.Equals(DBNull.Value) Then
                If Convert.ToDecimal(LengthTopXD) < 5.0201 Then
                    e.Item.Cells(3).BackColor = Color.Red
                End If


                If Not LengthTopXD.Equals(DBNull.Value) Then
                    If Convert.ToDecimal(LengthTopXD) > 5.0397 Then
                        e.Item.Cells(3).BackColor = Color.Red
                    End If


                    'Conditional Formatting for Marginal - Length Top XD (Yellow):

                    If Not LengthTopXD.Equals(DBNull.Value) Then
                        If Convert.ToDecimal(LengthTopXD) >= 5.0201 <= 5.02209999999 Then
                            e.Item.Cells(3).BackColor = Color.Yellow
                        End If

                    End If

                    If Not LengthTopXD.Equals(DBNull.Value) Then
                        If Convert.ToDecimal(LengthTopXD) >= 5.03770000001 <= 5.0397 Then
                            e.Item.Cells(3).BackColor = Color.Yellow

                        End If


                    End If

I know I am mising an easy solution here, but I need a 2nd pair of eyes to see it for me, thanks everyone!

Kai-What?
 
Why not just use a Case statement? e.g.
Code:
Select Case LengthTopXD

  Case 0 To 5.0200
  ' Color Red...

  Case 5.0201 To 5.02209999999
  ' Color Yellow

  etc...

End Select


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Genius! I cannot thank you enough ca8msm!

Kai-What?
 
Thanks
Ive been trying to figure out why & Wont work


Select Case Zone
Case Is <= 4 >= 5 <--- This only recognizes <= 4 all the time!!
CurrentRGSelection = WWTP
Case Is = 6
CurrentRGSelection = FireStation6
Case Is = 7
CurrentRGSelection = WWTP
End Select

Thanks!
Jason
 
case statements must contain exactly 1 condition.
switch (zone)
{
case 1:
case 2:
case 3:
default:
}

if you want a range you must use an if/then/else statement

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
In VB you can have ranges in CASE statments using IS and TO, not sure if it is different in C#. But you still haven't explianed what type of "range" you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top