Elimination Columns in DataView.

G

gobinath

Hi All,

From the Documentation of DataView - I infer that there is a RowSelection
and Column Sorting mechanism but no Column Selection mechanism. Say I want
to create 2 dataviews each looking at different set of columns from the same
dataset How do I do it???

Thanks in advance.
Gobi.
 
M

Miha Markic [MVP C#]

Hi,

DataView is basically a view on DataTable with features like filtering and
sorting.
You can't pick the columns you want as this doesn't make much sense anyway.
Instead you should pick your columns at the UI level.
 
W

W.G. Ryan - MVP

There isn't a mechanism to filter on columns unfortunately. Is this
requirement a UI issue (you only want certain things displayed) or a
logical one (ie you are iterating through a collection or something). If
it's the former, than you should just address it w/ UI tools like hiding
columns in the datagrid. If you need it b/c of programming logic, then the
only way to do it is to create a datatable and copy over the values you
want. This is a performance pig though unless you are dealing with a
relatively small number of objects and are pretty sure that the rows
involved won't be large in number.

HTH,

Bill
 
G

gobinath

Thanks All for the reply.

I'm just experimenting with the dataset stuff for the new UI's we are going
to develop.

If I associate the datatable with the datagrid, setting the datatablestyle
to delete a few columns, will there be any overhead while I'm updating the
columns which are not shown(ie deleted) from the datagrid.

Also interested in knowing why the column elimination is not possible. If
you can refer to some article or something. It would be of great help.

Thanks again for your replies.
Gobi.
 
C

Cor Ligthert [MVP]

Gobinath,
Also interested in knowing why the column elimination is not possible. If
you can refer to some article or something. It would be of great help.
Because there is no need for that. The dataview is a view on a datatable. If
you use that it is easy to eliminate the showing by not using it by one/two
column controls or by eliminating the columns by using the mapping either
direct or by using columnstyles.

For the most easy one see this most simple sample. (There are a lot of
samples using the columnstyle on our website)

http://www.windowsformsdatagridhelp.com/default.aspx?ID=76a81eb8-ea2d-48f4-99c3-a3539697edbd

I hope this helps,

Cor
 
W

W.G. Ryan - MVP

gobinath said:
Thanks All for the reply.

I'm just experimenting with the dataset stuff for the new UI's we are
going to develop.

If I associate the datatable with the datagrid, setting the datatablestyle
to delete a few columns, will there be any overhead while I'm updating the
columns which are not shown(ie deleted) from the datagrid.
Yes, but the overhead is trivial. And it's not something that you would do
in a loop for instance, typically you'd set it whenever the form loads or
the control loads - so the tiny performance hit honestly isn't a real issue.
Also interested in knowing why the column elimination is not possible. If
you can refer to some article or something. It would be of great help.
My guess is b/c there's more important issues at bat that people are
clammoring for. I agree, it would be nice but in most instances the need
for this to happen is because of UI concerns and as I mentioned originally,
there are plenty of ways to address it if the need is solely based on UI
reasons. Otherwise, you can just iterate through the view and only address
whatever columns you needed and just ignore the rest of them. If you were
able to remove columns, you'd definitely need to have either a different
constructor or you'd have to call Delete or something for each one. This
wouldn't be very efficient and unless you did it in the constructor, it
would be pretty messy. Someday down the road there may be a dataview that
can 'see' more than one table or allow you to specify the columns you want,
but there are so many other things they're working on that I wouldn't hold
me breath. Not that your point isn't valid, it's just that you aren't
really stopped from doing anything necessary b/c of the current limitation -
and there are some other areas that get in the way of how people do things.
 

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