C# GetCellValue not working

I have a data grid that I am trying to change the color of a row if a column in the grid has a particular value.  In the code below the YELLOW and PURPLE seem to work but I can't get the BLUE to work.....Now I know the obvious answer is that there must be no BLUE values in that column.  Even when I update table set tirhicolr ="BLUE".   I still get no BLUE rows.

Any suggestion on how to troubleshoot this or is there something wrong in my code?

Thanks for your help in advance.
void ptinventUltraGrid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
        {



//setting cell colors

            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "YELLOW")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Yellow;
            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "BLUE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.AliceBlue;
            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "PURPLE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Purple;
            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "AQUA")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Aqua;

            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "GREEN")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Green;

            }

            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "ORANGE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Orange;
            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "NONE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.White;
            }

            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == "")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.White;

            }
            if (e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString() == null)
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.White;

Open in new window

BBQMemphisAsked:
Who is Participating?
 
Miguel OzConnect With a Mentor Software EngineerCommented:
I am wodnring if you have a hidden ccharacter somewhere. Please replace:
 else if (targetValue == "BLUE")
with
 else if (targetValue.Contains("BLUE"))
   {
                e.Row.Appearance.BackColor = System.Drawing.Color.AliceBlue;  //Put a breakpoint here
    }

If you get the breakpoint then your logic is right but if the colour does not change then AliceBlue is not supported as BackColor.
0
 
Miguel OzSoftware EngineerCommented:
Try:
string targetValue = e.Row.GetCellValue(e.Row.Band.Columns["tirhicolor"]).ToString();
Debug.WriteLine("My target color is: " + targetValue);
// then your code

Also try to use targetValue (to avoid calculating this value all over again - more efficient)  and else if constructs instead of just if: (eg. the first 3 if)
           if (targetValue  == "YELLOW")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Yellow;
            }
            else if (targetValue == "BLUE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.AliceBlue;
            }
            else if (targetValue  == "PURPLE")
            {
                e.Row.Appearance.BackColor = System.Drawing.Color.Purple;
            }
  // continue with elseif or else



0
 
käµfm³d 👽Commented:
Which browser are you checking in? I know that when I was trying to get a row color to work I ended up up having to set the color for each cell in the row. The row color would work in FF, but not in IE (or maybe vice versa, I can't remember--but it worked in one and not the other)
0
 
BBQMemphisAuthor Commented:
thanks for your help.  1) kaufmed this is a windows form

2)  mas_oz2003 - I took your suggestion and even added this

 MessageBox.Show(targetValue);

Ran the form and I get BLUE in the message box but no blue on the form.  

i even changed some of date from YELLOW to BLUE and the old one that was a yellow now displays as White not BLUE.   I am at a loss with this...again thanks
0
 
BBQMemphisAuthor Commented:
thanks .....CONTAINS resolved the issue.  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.