Welcome to the Xceed Community | Help
Community Search  
More Search Options

Programmatically changing individual DataCell colours based on data in other DataRows

Page 2 of 2 (24 items)   < Previous 1 2
Sort Posts: Previous Next
  •  10-14-2009, 3:46 PM Post no. 24495 in reply to 24468

    Coffee [C] Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Hi Trevor, thanks again for your assistance and for the modified example project.

    I see that your example changes the background colour of cells based on the previous column in the same row.  What I was actually after was to change the background colour of cells based the same column in the previous row.  Not to worry, your project proved very helpful and I was able to modify the HighlightSeriesChangeConverter class to accommodate my needs.  See attached example.

    However, the disabling of cell virtualisation doesn't seem to have worked.  In both your example project and the one I have attached, the cells still don't retain their original background colour when the columns are sorted or the rows grouped, etc.

    Is there still something missing to fix this?

    Thanks,

    Jason


    Associate, .NET Development
    Morgan Stanley, UK
  •  10-18-2009, 11:34 PM Post no. 24571 in reply to 24495

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Hi Jason,

    I mentioned in an earlier post that the value convertor only seems to be called when the grid is initially loaded. In my case sorting and grouping is not permitted so I haven't explored that aspect. I would have thought though that events are available that could be used to force the re-rendering of the cells when data is sorted or grouped but I don't know what they are. Maybe have a look for something in the underlying view rather than the grid itself that you can hook in to.

    Regards,

    Trevor
  •  11-16-2009, 11:24 AM Post no. 24877 in reply to 24468

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Hi Trevor,

                    I have read your reply and test your attached example. Its working fine but when I sort or filter, then the conditional formating is not working fine. Can you please help me what to write in code so that it should work in filter , sorting and grouping also.

    Thanks & Regards,

    Mukesh Wadhwa

  •  11-17-2009, 4:45 AM Post no. 24887 in reply to 24877

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Hi Mukesh,

    As mentioned in my previous post my use case didn't require sorting or grouping (or filtering) so I didn't invesitgate how the solution might be invoked in such cases.  I also suggested investigating events that might be raised when such actions occur to see if grid presentation can be triggered for re-rendering. That may be the best place for you to start (or maybe other posts exist in the forum covering this aspect).

    Kind Regards,

    Trevor

  •  12-10-2009, 7:46 PM Post no. 25154 in reply to 24887

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Any update on this?  I'm going to resort to disabling sorting, grouping and filtering in my grid if no one has an answer to resolve the recycling of cells.

    Any help greatly appreciated if there is a way to resolve this at all.


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-09-2010, 8:13 PM Post no. 26045 in reply to 25154

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    With Mohamed's help offline, I have got a little bit further by using an IMultiValueConverter instead of an IValueConverter, but still not resolved the main issue.  I noticed that using IMultiValueConverter resulted in the HighlightSeriesChangeConverter.Convert() function being run every time a column was sorted, which didn't happen when IValueConverter was being used. This isn't desired as I don't wish the cells' background colours to be re-evaluated every time the layout changes as they are based on the relative values between rows upon their initial sort order. So I have added a 'Fix' button to stop the HighlightSeriesChangeConverter.Convert() function being run before any grouping or sorting takes place.

    I have attached an updated example based on these changes.

    I have also raised a further issue concerning running this converter when there are lots of data: http://xceed.com/CS/forums/thread/26044.aspx


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-09-2010, 8:27 PM Post no. 26046 in reply to 26045

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    I've attached the latest example project showing the code I am trying to get to work using the IMultiValueConverter solution.

    Sorting, grouping or filtering the columns results in the background colours of the cells being completely randomised.  This does not seem like correct behaviour.


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-11-2010, 6:40 PM Post no. 26080 in reply to 26046

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Based on some offline support from Jenny (see below), I have now created a working project that allows me to sort, group and filter the grid without the cell colours becoming randomised.  It was simply a matter of returning DependencyProperty.UnsetValue from the converter instead of cell.Background.

    I have attached the example project.  However, I am still having one more problem with it.  If I change the view to TableflowView, an error occurs in the converter.  The DataCell.DataContext is no longer a DataRowView, it is an EmptyDataItem.

    How do I resolve this?

    Thanks,

    Jason

    PS: The solution Jenny provided where highlighting is based on visual row versus the source wasn't required for my project, so I haven't implemented this part of the solution, only the return value of the converter.

     

    Offline support from Jenny:

    It's a bit tricky in the converter to return the Cell.Background of something you are in fact using the converter for.

     

    The correct way to tell it to revert to its default value in a converter is to return DependencyProperty.UnsetValue;

     

    So, if you replace "return cell.Background;" with "return DependencyProperty.UnsetValue;" things should start to work better.

     

    Second, you use row.Table.Rows.IndexOf(row) in your converter, which will give you the position based on the original order of the table. Meaning that your highlight will not be based on the previous visual row. If you want to get the index of the row vs the source (the DataGridCollectionView), you can use "(xcdg:DataGridVirtualizingPanel.ItemIndex)".

     

    Here is an example with your code :

     

    <Style TargetType="{x:Type xcdg:DataCell}">

      <Setter Property="Background">

          <Setter.Value>

            <MultiBinding Converter="{StaticResource highlightSeriesChangeConverter}">

                <Binding Mode="OneWay" RelativeSource="{RelativeSource Self}" />

                <Binding Mode="OneWay" RelativeSource="{RelativeSource Self}" Path="Content" />

                <Binding Mode="OneWay" RelativeSource="{RelativeSource Self}" Path="DataContext" />

                <Binding Mode="OneWay" RelativeSource="{RelativeSource Self}" Path="ParentRow.(xcdg:DataGridVirtualizingPanel.ItemIndex)" />

            </MultiBinding>

          </Setter.Value>

      </Setter>

    </Style>

     

    And after, just use that new info into your converter.

     


    Associate, .NET Development
    Morgan Stanley, UK
  •  03-16-2010, 3:32 PM Post no. 26136 in reply to 26080

    Re: Programmatically changing individual DataCell colours based on data in other DataRows

    Solution found as per http://xceed.com/CS/forums/thread/26044.aspx
    Associate, .NET Development
    Morgan Stanley, UK
Page 2 of 2 (24 items)   < Previous 1 2
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.