Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Cell Background color issue
posted

Hello,

I have my view's XamDataGrid bound to DataTable in my ViewModel. Few columns (E.g. C1, C2) in this grid are editable. Users can change values in those columns (E.g. Row1 C1 changed) and once they hit Submit button, I close the control and open same control again with same data, but want to change the background color of the cell (i.e. Row1 C1) to highlight that this value was modified. The way I thought of doing it is:

1) Once user change the value, in my EditModeEnded event, I get the background DataRow (of DataTable) and in Tag column, I put the column name that was changed (i.e. C1)

2) I pass the same data set again for 2nd time confirmation view opening and want to look at Tag column and highlight all cells that were changed.

Please tell me if this is the right approach of doing it and also a sample code would be beneficial.

Thanks.

  • 1500
    Offline posted
    Hello,
    If you would like to, you can be setting custom tags for each cell, and then modify the cell appearance via its CellValuePresenter style. Following the steps you have provided, you can set the tag from the EditModeEnding event like this:
    var oldValue = e.Cell.Value.ToString();
    var newValue = e.Editor.Value.ToString();
    if (oldValue != newValue)
     {
       CellValuePresenter cvp = CellValuePresenter.FromCell(e.Cell);
       cvp.Tag = "Changed";
     }
    And then set up a style to apply background color based on the tag of the CVP:
                    <Style TargetType="{x:Type igDP:CellValuePresenter}">
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag}" Value="Changed">
                                <Setter Property="Background" Value="Yellow"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
    Please note that XamDataGrid as a visual element is part of the View, and will not know about changes made to your Model. As you have said that your application will be closing and re-opening, you will have to implement a save/load logic based on your needs.
    Should you have any further questions or concerns, please let me know.
    Sincerely,
    Tihomir Tonev
    Associate Software Developer
    Infragistics