This is a migrated thread and some comments may be shown as answers.

cells forecolor and backcolor taking random values on refresh

8 Answers 123 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Yaroslav
Top achievements
Rank 1
Yaroslav asked on 27 Feb 2012, 12:01 PM
Hi, using the sample provided on the link GridView, formatting cells I'm trying to dinamically change cells foreground.

The color is changed indeed but then I'm having a big problem. When I scroll the grid, either horizontally or vertically, diferent cells, other than the one I changed, change also their foreground color to the one I'm using. Same problem with the background color of the cell.

Here is a code snippet showing the funcionality I'm trying to achieve, very similar to the sample provided on the link.

Select Case e.Column.Name
    Case "TestID"
       Select Case e.Row.Cells("Status").Value
            Case 1
                e.CellElement.ForeColor = Color.Green
            Case Else
                e.CellElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local)
    End Select
End Select

8 Answers, 1 is accepted

Sort by
0
Accepted
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 27 Feb 2012, 02:17 PM

Hi Yaroslav,

due to the internal reuse of Cells in the Grid, once you use the CellFormatting Event, you have to reset changes to all cells.

In your case, you have to call the Reset Function for all Cells not just for Column 'TestID'.

Regards
Erwin

0
Yaroslav
Top achievements
Rank 1
answered on 27 Feb 2012, 03:00 PM
Thanks, you saved my day.

And just to extend a little bit more the question. I created a enum set to declare several colors, here is a code snippet
    Public Enum ColorStatus
        First = &HFF1308&
        Second = &HFFFFFF&
    End Enum
 
e.CellElement.RowInfo.Cells("Status").Style.ForeColor = System.Drawing.ColorTranslator.FromHtml(ColorStatus.First)

Then I apply one of the colors to a cell (the one that was causing problems) but the ColorTranslator.FromHtml is not recognizing the colors. Any clue?
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 27 Feb 2012, 06:52 PM
Glad I could be of help. Can't help you with the second question since I'm a C# guy.

According to
http://msdn.microsoft.com/de-de/library/system.drawing.colortranslator.fromhtml.aspx
you have to supply a string value.

Regards
Erwin

0
Yaroslav
Top achievements
Rank 1
answered on 28 Feb 2012, 08:28 AM
Thanks again, I will give it a try
0
Accepted
Ivan Petrov
Telerik team
answered on 01 Mar 2012, 10:04 AM
Hello guys,

Thank you both for writing.

I am glad you have been able to found your way through Yaroslav's first problem. 
On the second problem. First, some background. A color value needs 32 bits to store its value. Integer values are 32 bits, but one is reserved for the sign and an integer cannot store all possible color values. You can store only the RGB values of the color in an int, but when you format it into a color string, it will be transformed with leading zeroes which is how it is represented in memory and you will get a transparent color. For this purpose you need a unsigned integer where all 32 bits are used for storing data. Unfortunately, you cannot use unsigned integers as values for an enumeration. A possible solution would be to store the RGB values in a enumeration and then to add it to a unsigned integer with leading FF instead of 00 so you would get the actual color. Here is an example of this:
Enum ColorStatus
  First = &Hff1308
  Second = &Hffffff
End Enum
 
Dim colorValue As UInteger = &HFF000000UI + CInt(ColorStatus.First)
e.CellElement.RowInfo.Cells("Status").Style.ForeColor = System.Drawing.ColorTranslator.FromHtml(String.Format("#{0:X}", colorValue))

I hope this will be useful for you. Should you have further questions, I would be glad to help.

Greetings,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Yaroslav
Top achievements
Rank 1
answered on 04 Apr 2012, 02:58 PM
Hi, I unsubscribed from this thread but came back to it to refresh the reset issue and saw the Ivan Petrov answer...thanks very much! it is perfectly working now, I can use enumerates to handle my different status colors for all the app.
0
Yaroslav
Top achievements
Rank 1
answered on 09 Apr 2012, 02:24 PM
I'm having again the refresh issue on my grids. Whenever I scroll right and then left many of the icons I'm displaying on the cells are repeated on other cells. This is causing me problems as not only is drawing icons where there none but also where I have inactive cells (grayed icon) is painting the enabled icon, but the button remains grayed.

Tried ther reset recommendation from Erwin but is not working.

Thanks!
0
Stefan
Telerik team
answered on 12 Apr 2012, 12:26 PM
Hello Yaroslav,

Thank you for writing back.

The ResetValue method should reset the styles for the cells and prevent such a behavior. Since you are mentioning this does not work in your case, I will need to ask you for a sample project demonstrating this issue, so I can investigate it locally and provide you with adequate support. You will need to open a new support ticket, where attachments are allowed. Please mention this forum thread in the ticket as well.
 
Regards,
Stefan
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Yaroslav
Top achievements
Rank 1
Answers by
erwin
Top achievements
Rank 1
Veteran
Iron
Yaroslav
Top achievements
Rank 1
Ivan Petrov
Telerik team
Stefan
Telerik team
Share this question
or