DataView.Rowfilter filtering parent-form's dataset

375 Views Asked by At

I am trying to filter my dataview. So I've got the following event-handler:

private void Break_ValueChanged(object sender, EventArgs e)
  {
     DataView dvBreaks = ParentForm.CurrentUser.Cache.GetERPLuTableFromCache( Db.CustomDbMetaData.CachedTables.Breaks ).DefaultView;
     if( Convert.ToString( Break.Value ) != string.Empty ) {
        dvBreaks.RowFilter = "BREAK = '" + Convert.ToString( Break.Value ) + "'";
     }
  }

When I look at this code, my understanding is that it should ONLY be filtering the data in dvBreaks, however the data in the parent form is actually being filtered. I could work around this issue with a loop but I thought it would be nice to use less code - and maybe make this process more efficient.

Can anyone shed some light on this for me?

1

There are 1 best solutions below

0
On BEST ANSWER

It's filtering the parent form because you're grabbing the reference from the parent form. If you want it to only filter the child then you'll need a copy of that for the child and use that copy to data bind.

You could change the code like this:

private void Break_ValueChanged(object sender, EventArgs e)
{
    DataView dvBreaks = ParentForm.CurrentUser
        .Cache
        .GetERPLuTableFromCache( Db.CustomDbMetaData.CachedTables.Breaks )
        .DefaultView
        .ToTable()
        .DefaultView;

    if( Convert.ToString( Break.Value ) != string.Empty ) {
        dvBreaks.RowFilter = "BREAK = '" + Convert.ToString( Break.Value ) + "'";
    }
}

or, if GetERPLuTableFromCache is a DataTable:

DataView dvBreaks = ParentForm.CurrentUser
    .Cache
    .GetERPLuTableFromCache( Db.CustomDbMetaData.CachedTables.Breaks )
    .Copy()
    .DefaultView;