This is a migrated thread and some comments may be shown as answers.

Grid redraw event

2 Answers 133 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ESA
Top achievements
Rank 1
ESA asked on 10 Aug 2011, 08:09 PM
I am binding the grid view to a data table via ItemsSource. Everything is OK, however, the changes to the data source don't go only through the grid user interface, but may happen also by making programatic changes directly to the data source. For example a menu option may go trough some data table fields and change their values, or may add new rows to the data table. In that case I want the grid to be notified about the changes in those affected areas and redraw itself to show the changes. However, I cannot find any method that would sound like "Redraw" or "Invalidate". There is a method Rebind which actually does the job and which I am using, however, why do I want to rebind the entire grid if I am changing only one field? I want to redraw its corresponding cell only rather than rebinding the entire grid.
Is there any method, or a subscription to an event, where I can have the grid redraw specified areas.
Any code samples?
Thank you,
Cezar Mart

P.S. I investigated it in the meantime, and I learned I need to implement INotifyCollectionChanged in my DataTable.
Great, I did this way:
public class MyDataTable : DataTable, INotifyCollectionChanged
{

  protected override void OnRowChanged ( DataRowChangeEventArgs e )
  {
   base.OnRowChanged(e);
   if ( e.Action == DataRowAction.Add )
   {
    if ( CollectionChanged != null )
    {
     CollectionChanged ( this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add) );
    }
   }
  }

  public event NotifyCollectionChangedEventHandler CollectionChanged;


}

and later in the code:
MyDataTable tb = new MyDataTable();
grid.ItemSource = tb; // grid is of type RadGridView

Then I programatically add a new row to my data table and the OnRowChanged is invoked. Great, however, the CollectionChanged handler is always null, so it looks the grid is not listening to this event. How do I make listen?

Thanks

2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 11 Aug 2011, 12:58 PM
Hi Tracey,

I believe there is a simpler solution .

Please use data table as items source , but bind the grid to its DefaultView instead of directly to the DataTable.  You do not need to implement the INotifyPropertyChanged changed interface as the DefaultView already does that for you.

MyRadGridView.ItemsSource = MyDataTable.DefaultView.

Best wishes,
Pavel Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
ESA
Top achievements
Rank 1
answered on 11 Aug 2011, 05:21 PM
Thank you Pavel! :)
Tags
GridView
Asked by
ESA
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
ESA
Top achievements
Rank 1
Share this question
or