Home Forums WinForms controls Xceed Grid for WinForms Sorting messes up alternate row styles

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #16646 |

    I have two datarow templates applied to a GridControl, to alternate row BackColors (white/grey). But when I sort the rows, the colors get messed up. Some of a row will be white, some grey. Looks like the datarow template style is being applied to each cell as the column sorts, rather than at the end of the operation, giving inconsistent styles applied across a row.

    Imported from legacy forums. Posted by RJ (had 1152 views)

    User (Old forums)
    Member
    Post count: 23064

    How do you apply the row style to the grid?  If you do it in one of the following two ways, it should work fine :

    gridControl1.ApplyStyleSheet(

    StyleSheet.Tan );

    //or

    gridControl1.DataRowTemplateStyles.Add(

    new VisualGridElementStyle() );

    gridControl1.DataRowTemplateStyles.Add(

    new VisualGridElementStyle() );

    gridControl1.DataRowTemplateStyles[ 0 ].BackColor =

    Color.Blue;

    gridControl1.DataRowTemplateStyles[ 1 ].BackColor =

    Color.Red;

     

    Imported from legacy forums. Posted by André (had 272 views)

    User (Old forums)
    Member
    Post count: 23064

    I actually created the styles using the designer. So, the code resembles your second example, except that the styles are created before .Add is called.

    I am adding data to the grid manually using DataRows.AddNew()

     

    If a column is initially set to sort, or I subsequently click a column header to sort, the cell backcolours get scattered around the grid, the color no longer applies to a row.

    Imported from legacy forums. Posted by RJ (had 398 views)

    User (Old forums)
    Member
    Post count: 23064

    This should not matter.  The style should apply whether you feed the grid manually or via a DataSet.

    Can you attached a sample application reproducing the issue to this thread (via the option tab), so we can investigate this further?

    Imported from legacy forums. Posted by André (had 283 views)

    User (Old forums)
    Member
    Post count: 23064

    I have investigated further, and I think the problem is related to some events I handle which try to change the backcolor of the row. e.g; if the cell value increases, show the cell green for a second, then change back to what it was.

    Problem seems to be releated to setting the color *back* to what it was. I am using cell.parentrow.backcolor to find what I should set the color back to, but I think the order of events is giving me the wrong result in some cases, while I am sorting.

     Do you have any tips on how/what I should do to resolve this?

    Imported from legacy forums. Posted by RJ (had 315 views)

    User (Old forums)
    Member
    Post count: 23064

    I may have resolved this by using

    cell.ParentRow.GetDisplayVisualStyle(VisualGridElementState.InactiveSelection).BackColor

     

    instead of cell.ParentRow.BackColor to reset the cell color… does that sound right?

    Imported from legacy forums. Posted by RJ (had 360 views)

    User (Old forums)
    Member
    Post count: 23064

    Hmmm… nope problem still exists, but not as obvious, I’m guessing just with the timings of when cells colors are updated.

     

     

    Imported from legacy forums. Posted by RJ (had 283 views)

    User (Old forums)
    Member
    Post count: 23064

    Have you tried using the ResetBackColor() method on the ParentRow?

    Imported from legacy forums. Posted by André (had 405 views)

    User (Old forums)
    Member
    Post count: 23064

    That seems to have done the trick, thanks!

    Imported from legacy forums. Posted by RJ (had 1238 views)

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.