RowFilter and Filtered Records

  • Thread starter Thread starter Scott Carter
  • Start date Start date
S

Scott Carter

I have a DataTable that I'm applying a filter to using
DataTable.DefaultView.RowFilter. After this when I look at
DataTable.DefaultView.Count, I get the correct count for the filtered
records. The problem is when I start iterating through
DataTable.DefaultView.DataViewManager.DataSet.Tables[0], I get records that
should be filtered out.

I'm using this same process on 2 different tables. It all works correctly on
1 of them, but not the other and I haven't been able to figure out what the
difference is. Any ideas are much appreciated!

Scott
 
Scott Carter said:
I have a DataTable that I'm applying a filter to using
DataTable.DefaultView.RowFilter. After this when I look at
DataTable.DefaultView.Count, I get the correct count for the filtered
records. The problem is when I start iterating through
DataTable.DefaultView.DataViewManager.DataSet.Tables[0], I get records that
should be filtered out.

The DataSet property of a DataViewManager refers to the actual DataSet used
to create it. That's the _full_ DataSet, with all the tables, none of which
are filtered in any way.
 
Thanks John,

I've taken care of this another way now, but I'm really curious if there's
not a way to retrieve only the filtered records. Is there a flag on the rows
that let me know if they're currently filtered or not? How do data bound
grids limit the filtered records? ...There must be something that I'm
missing here.

Scott
I have a DataTable that I'm applying a filter to using
DataTable.DefaultView.RowFilter. After this when I look at
DataTable.DefaultView.Count, I get the correct count for the filtered
records. The problem is when I start iterating through
DataTable.DefaultView.DataViewManager.DataSet.Tables[0], I get records that
should be filtered out.

The DataSet property of a DataViewManager refers to the actual DataSet used
to create it. That's the _full_ DataSet, with all the tables, none of which
are filtered in any way.
 
Scott Carter said:
Thanks John,

I've taken care of this another way now, but I'm really curious if there's
not a way to retrieve only the filtered records. Is there a flag on the rows
that let me know if they're currently filtered or not? How do data bound
grids limit the filtered records? ...There must be something that I'm
missing here.

Scott
I have a DataTable that I'm applying a filter to using
DataTable.DefaultView.RowFilter. After this when I look at
DataTable.DefaultView.Count, I get the correct count for the filtered
records. The problem is when I start iterating through
DataTable.DefaultView.DataViewManager.DataSet.Tables[0], I get records that
should be filtered out.

The DataSet property of a DataViewManager refers to the actual DataSet used
to create it. That's the _full_ DataSet, with all the tables, none of which
are filtered in any way.

Filtering is a function of the DataView class. Even when you bind a DataSet
to a grid, it uses a DataView object internally.
 
The Table property of DataView class gets the full original table you
created the DataView from. To iterate over the records after applying
the RowFilter, you should use the GetEnumerator method of the
DataView. When you iterate using the enumerator, you will get
DataRowView objects, which in turn have a Data Row property. Thus you
can get the filtered rows. e.g.

IEnumerator ie = dv.GetEnumerator();
while( ie.MoveNext() )
{

DataRowView drv = (DataRowView)ie.Current;
DataRow dr = drv.Row;
...
}

sid_c

John Saunders said:
Scott Carter said:
Thanks John,

I've taken care of this another way now, but I'm really curious if there's
not a way to retrieve only the filtered records. Is there a flag on the rows
that let me know if they're currently filtered or not? How do data bound
grids limit the filtered records? ...There must be something that I'm
missing here.

Scott
I have a DataTable that I'm applying a filter to using
DataTable.DefaultView.RowFilter. After this when I look at
DataTable.DefaultView.Count, I get the correct count for the filtered
records. The problem is when I start iterating through
DataTable.DefaultView.DataViewManager.DataSet.Tables[0], I get records that
should be filtered out.

The DataSet property of a DataViewManager refers to the actual DataSet used
to create it. That's the _full_ DataSet, with all the tables, none of which
are filtered in any way.

Filtering is a function of the DataView class. Even when you bind a DataSet
to a grid, it uses a DataView object internally.
 
Back
Top