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
{
}
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
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