DataGrid refresh proper way

Apr 28, 2010 at 12:32 PM

Could you please advice what is the proper way of refreshing grid content?

Let's assume there is DataGridView dataGridView and it's initialized this way:

ObjectContext context = Session.Current.ObjectContext;
ObjectSet<Table1> oc = context.GetObjectSet<Table1>( );

dataGridView.AutoGenerateColumns = false;
dataGridView.DataSource = bindingSource;
bindingSource.DataSource = oc;

Then inside a button onclick event procedure:

ObjectSet<Table1> z = new ObjectSet<Table1>( );

z.AddRange(
    oc,
    delegate( Table1 table1 ) {
        return (table1.Field1 == comboBox.Text);
    } );

bindingSource.DataSource = z;

It works, but it's not the proper way - I mean "bindingSource.DataSource = z".
I prefer to update oc and refresh the grid using CurrencyManager.

 

<Table1>
Coordinator
May 3, 2010 at 12:18 AM
Edited May 3, 2010 at 12:18 AM

Did you try with the ConcurrencManager? What problem did you face?

May 4, 2010 at 8:32 AM
Edited May 4, 2010 at 10:07 AM

Yes, I tried the sequence:

 

CurrencyManager cm = (CurrencyManager)dataGridView.BindingContext[bindingSource];
if(cm != null) cm.Refresh();

 

- no errors and no effect

update:added the following assigment in the code

z.AddRange(
    oc,
    delegate( Table1 table1 ) {
        return (table1.Field1 == comboBox.Text);
    } );

oc = z;
// oc assined to bindingSource.DataSource second time
bindingSource.DataSource = oc;

CurrencyManager cm = (CurrencyManager)this.BindingContext[bindingSource];
if(null != cm) cm.Refresh( );
// now works