DataView Question

S

SLN

Ok, I have a dataview that may or may not have a rowfilter. If I do have a
rowfilter applied, how can I quickly find out what the total number of rows
are from the unfiltered state.

A user can take actions against records during either state, but I need to
accurately display both the total records in the view (unfiltered) and
(filtered) at ALL TIMES.

Please help..
 
D

David Sceppa

To see how many rows are in the DataTable, check
DataView.Table.Rows.Count.

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2004 Microsoft Corporation. All rights reserved.
 
S

Steve Nesbit

That is a great answer, but I found 1 issue with our system that most likely
won't allow it.
We present 3 grids, from 1 base datatable. Each grid is populated from its
own dataview and that dataview has a rowfilter in order to distinguish
itself from the start.

When we turn on user filtering facility, it adds to the currently defined
rowfilter to properly reflect the user's wishes. Therefore getting the
underlying number of rows from the datatable would not return a correct
answer.

I have found a way around this, in that when action are taken by the user
that effects the total number of records for a specific grid (those with
only a base rowfilter), I increment or decrement the counts versus
attempting to query them.

Querying them just won't work in this situation. A nice future feature for
ado.net would be do have defined levels of rowfilters. With each subsequent
level narrowing the choices. In this scenario, there would be methods or
properties that would allow you to query the counts based on specific
rowfilters that are applied, or in aggregate if needed.

This feature would be very helpfull!!!!

Thanks for all of your help..

sln
 
W

William Ryan eMVP

Steve:

The DataTable's Rows.Count is totally isolated from the rowfilter. Nothing
you can do via the Rowfilter will have any effect on this whatsoever. If
DataView dv = myDataTable.DefaultView;

then anything you do to DV via a rowfilter won't affect myDataTable.
I'm not sure I understand your problem, but regardless of how it was
implemented, you should be good to go. I have x = myDatatable.Rows.Count.
Now, I create 3 views, a, b, and c, all based on myDataTable. If I apply a
filter to a, I can use a.Count to get that number. Now I can apply another
filter to b, again retrieving b.Count. If I need the filter to be
cumulative, then I can simply concatenate the conditions, provided of course
that they don't conflict with each other. If each is a subset of the first
then this won't be the case. finally I use c.Count. Since I grab each
value at each point when filter is set, the variably I use for each will in
fact hold the correct value as of the point in time the filter was applied.
All along the underlying datatable's rows.Count will never change. So you
can have each at a given point to get the respective value. Subtracting
that number from Rows.Count of the datatable will give you the number of
records NOT meething that condition and by applying everything with AND's
you can still get the cumulative effect. If you don't want it cumulatively,
then just don't use Ands.

HTH,

Bill

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top