Completed
Last Updated: 17 Aug 2015 11:02 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 15 Apr 2014 06:09
Category: GridView
Type: Bug Report
1
FIX. RadGridView - the RowFormatting event does not always fire when the grid data is changed
To reproduce:
Add a RadGridView and use the RowFormatting event for showing rows with errors. Use a timer to change the data. The RowFormatting  event fires when the user does not group rows. But after grouping the rows by any column, the grid is not refreshed according to the applied style in RowFormatting event. In order to reproduce the problem, use the following code:
private readonly BindingList<DataItem> _items = new BindingList<DataItem>();
private readonly Random _rnd = new Random();

public Form1()
{
    InitializeComponent();

    for (var i = 1; i <= 10; i++)
    {
        _items.Add(new DataItem("Text1 = " + i, "Type = None", _rnd.Next(0, 2) == 1));
    }
    radGridView1.DataSource = _items;

    timer1.Start();
}

private void radGridView1_RowFormatting(object sender, Telerik.WinControls.UI.RowFormattingEventArgs e)
{
    var item = e.RowElement.Data.DataBoundItem as DataItem;
    if (item != null && item.IsDataCorrect)
    {
        e.RowElement.ResetValue(VisualElement.ForeColorProperty, ValueResetFlags.Local);
    }
    else
    {
        e.RowElement.ForeColor = Color.Red;
    }
}

private void timer1_Tick(object sender, EventArgs e)
{
    foreach (var item in _items)
    {
        item.IsDataCorrect = _rnd.Next(0, 2) == 1;
    }
}


ic class DataItem : INotifyPropertyChanged

private bool _isDataCorrect;
private string _text;
private string _type;

public DataItem(string text1, string type, bool isOk)
{
    Text = text1;
    Type = type;
    IsDataCorrect = isOk;
}

public event PropertyChangedEventHandler PropertyChanged;

public bool IsDataCorrect
{
    get
    {
        return _isDataCorrect;
    }
    set
    {
        if (_isDataCorrect != value)
        {
            _isDataCorrect = value;
            OnPropertyChanged("IsDataCorrect");
        }
    }
}

public string Text
{
    get
    {
        return _text;
    }
    set
    {
        if (_text != value)
        {
            _text = value;
            OnPropertyChanged("Text1");
        }
    }
}

public string Type
{
    get
    {
        return _type;
    }
    set
    {
        if (_type != value)
        {
            _type = value;
            OnPropertyChanged("Type");
        }
    }
}

protected virtual void OnPropertyChanged(string propertyName)
{
    var handler = PropertyChanged;
    if (handler != null)
    {
        handler(this, new PropertyChangedEventArgs(propertyName));
    }
}
0 comments