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
20
Treegrid Change Record Color
posted

Hi guys

How can i change backcolor of each record in treegrid when somefield value change?

for example when "sum of all" field is larger than 100 , I want change backcolor of row to red

please help

Parents
No Data
Reply
  • 6365
    Offline posted

    Hello Rahman,

    In order to change the background color of a parent record in the XamTreeGrid based on a summary value for it's child records, you can simply access the respective DataRecordPresenter and set it's Background property.

    This manipulation can be done inside the InitializeRecord (for initial check) and the RecordUpdated (for runtime check) events, which will allow you to access the respective data and perform the check.


    private void dataGrid_RecordUpdated(object sender, Infragistics.Windows.DataPresenter.Events.RecordUpdatedEventArgs e)
    {
        var dr = e.Record as DataRecord;
        if (dr == null)
            return;

        var parentDr = dr.ParentDataRecord as DataRecord;
        if (parentDr == null)
            return;

        if (!(parentDr.DataItem is Person))
            return;

        // Recalculate.
        var person = parentDr.DataItem as Person;
        var sum = person.Items.Sum(i => i.Price);
        person.Price = sum;

        // Set background of parent.
        var parentPresenter = DataRecordPresenter.FromRecord(parentDr) as DataRecordPresenter;
        if (sum >= 1000)
            parentPresenter.Background = Brushes.Tomato;
        else
            parentPresenter.Background = Brushes.Transparent;
    }

    Another approach would be to use a Converter, along with a Style and you can take a look at that functionality at the "xamDataGrid > Display > Conditional Formatting" sample from our WPF Samples Browser.

    I have attached a sample application that uses the approach from above.

    If you have any further questions, please let me know.

    XamTreeGrid_sample.zip
Children
No Data