No DataView column filtering: design weakness?

L

LarryF

One purpose of the DataView is to allow the classes that manage the
data to limit the data provided to the classes that consume the data.
The DataView lets you filter by row, but not by column. My data layer
needs to provide two different views of of an XML data table to the
user interface layer, and each different view needs to display
different columns.

In threads in this group I've found three solutions to this problem
mentioned: duplicating the source DataTable, use SQL statements to
select the correct columns, or letting the user of the DataTable or
DataView (such as a DataGrid) do the filtering. Each of these solutions
have problems.

Duplicating the DataTable may work fine for read-only data, but it
doesn't work if users will be editing different views of the data. You
can't allow multiple copies of data to be edited.

Using SQL statements to select different columns works fine for data
that comes from a database, but my data is coming from an XML file.
There is no back-end database that will provide me restricted views of
my data.

You can use a DataGrid's TableStyles property to filter columns, and
any other grid worth using will let you filter by columns. The problem
with letting the data consumer do the filtering is that the consumer
should know only about the data it needs. If the data source has to
rely on the data consumer to filter columns, the data source gives the
consumer more information than it needs, and then it has to hope that
the consumer obeys the rules and doesn't modify the columns it isn't
supposed to.

Out of these three solutions, it seems that the only one that will work
for XML data is the third, hoping that the data consumers will not mess
with columns I think they shouldn't. This isn't a great solution.

Have I missed something, or did the designers of ADO.Net, by not
allowing column filtering, design a system that won't let the database
layer limit the view of the data consumers?
 
V

Val Mazur \(MVP\)

Hi,

If you can hide columns in a grid it is one of the ways to handle situation.
If you need to create a DataView with the specific columns, then you would
need to create another DataTable, based on existing one, delete the columns
you do not need and create DataView from it
 
L

LarryF

Hiding columns in the grid may be the best answer, but as I mentioned
in my first post, it violates the principle of data hiding.

Creating another DataTable, as I also mentioned, is a bad idea because
there is no easy way to synchronize edits in the two different
DataTables.

I still think that failing to allow column filtering in a DataView is a
design flaw.

Any other thoughts?
 
V

Val Mazur \(MVP\)

Hi,

Even if it is a design flow, you cannot delete the columns from the
DataView. You also cannot have same column that belongs to two different
DataTables and you will face synchronizing issue. Maybe you should create
DataTable from the database using different SQL statements and synchronize
data there
 

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