Can I temporarily highlight a field value change in a DevExpress TreeList control?

36 Views Asked by At

Is is possible to temporarily highlight a field value change in a DevExpress TreeList control ?

See: https://docs.devexpress.com/WindowsForms/DevExpress.XtraEditors.FormatConditionRuleDataUpdate

I have a bound TreeList control, bound to a hierarchical list of objects. I want to change the value of one object property, and have the corresponding row/column highlight temporarily.

Ultimately, I would like to re-assign the datasource for the TreeList, and have it highlight the cells that have changed, but I cannot seem to get the temporary highlighting to work.

I have tried this:

        treeList1.Parent = this;
        treeList1.Dock = DockStyle.Fill;
        treeList1.KeyFieldName = nameof(Part.PartId);
        treeList1.ParentFieldName = nameof(Part.ParentId);
        treeList1.OptionsBehavior.PopulateServiceColumns = true;
        treeList1.OptionsBehavior.ReadOnly = true;

        treeList1.DataSource = new[]
        {
            new Part{  PartId = 1, ParentId = default, Data = true},
            new Part{  PartId = 2, ParentId = 1, Data = true},
            new Part{  PartId = 3, ParentId = 1, Data = true},
        };

        var treeListFormatRule = new TreeListFormatRule
        {
            Column = treeList1.Columns[nameof(Part.Data)],
            Name = "Format1",
            Rule = new FormatConditionRuleDataUpdate
            {
                HighlightTime = 500,
                PredefinedName = "Green Fill",
                Trigger = FormatConditionDataUpdateTrigger.ValueChanged,
            }
        };

        treeList1.FormatRules.Add(treeListFormatRule);

    private void button2_Click(object sender, EventArgs e)
    {
        var parts = treelist1.DataSource as IEnumerable<Part>;
        var part = parts.First(p => p.PartId == 2);
        part.Data = false;
    }

I implemented INotifyPropertyChanged on my class, but it made no difference.

internal class Part : INotifyPropertyChanged
{
    public int ParentId { get; set; }
    public int PartId { get; set; }

    bool _data;
    public bool Data
    {
        get => _data;
        set
        {
            _data = value;
            OnPropertyChanged();
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
0

There are 0 best solutions below