Manually adding to DataView / Custom RowFilter

M

mikeorb

Am I correct that you can not create a DataView that has arbitrary
"pointer rows" referencing the underlying DataTable? Seems like an
oversight but maybe I am just dense.

I have a situation where RowFilter does not provide sufficient
functionality. So the only way I can find to create this "custom" view
of my data is to create a new table and copy data from the real table.

It would be nice to have a way for the RowFilter make use of callbacks
or some such to provide custom filtering. That would get me where I
need to be. Or just support manual creation somehow.

Regards,
-Mike
 
C

Cor Ligthert

Mike,

For Net 1.x versions
\\\
DataView dv = new DataView(dt);
dv.Sort = "bla"; // sorts column bla
DataTable dtnew = dt.Clone();
foreach (DataRowView dvr in dv)
dtnew.ImportRow(dvr.Row);
dt.Clear();
dt = dtnew.Copy();
///

In the Net 2 version there is a CopyTo command to copy it in one time to a
new datatable.

I hope this helps,

Cor
 
J

J L

Hi Cor,
A side question based on your answer...being new to .Net and needing
to build real apps now rather than later, I am spending considerable
time and effort to learn .Net 1.1 and to create my set of tools
(utilities, DAL, etc). Your response and several others sound like Net
2 is significantly different and better than 1.1

My questions are (1) would you advise getting the beta and working
against that and (2) given my time constraints (i.e. need to make a
real app real soon) will waiting for Net 2 be risky and possibly
buggy?

If others have a response, I would appreciate hearing the comments.

TIA,
John
 
C

Cor Ligthert

JL,

When you like to walk in the frontline, than go to 2005.

You will be sure that you have to find all extra's at the moment yourself
and probably will have less (qualified) help from the net and from
newsgroups..

Keep in mind that there are a lot more bullets to catch in the frontline.

Just my thought,

Cor
 
V

Val Mazur \(MVP\)

Hi,

Are you looking for something to point to the different dataRows in a
DataTable, that do not have anything common in a filtering? There is no
direct way to do this, but what you could do is to create additional column
in a DataTable with the unique id. Then you could create filter string with
the list of these IDs. It would allow to
filter DataTable using any combination of the rows, but potentially it could
lead to the long filter strings.
 
J

J L

Thanks Cor,
I understand. I often say that I want to be on the leading edge and
not the bleeding edge. With MicroSoft that usually means 2 or 3 SP's
after release.

John
 
M

mikeorb

Val said:
Are you looking for something to point to the different dataRows in a
DataTable, that do not have anything common in a filtering?

Really that the RowFilter property can not represent it.
There is no
direct way to do this, but what you could do is to create additional column
in a DataTable with the unique id. Then you could create filter string with
the list of these IDs. It would allow to
filter DataTable using any combination of the rows, but potentially it could
lead to the long filter strings.

Yeah, I thought about this since there is a unique key column but was
too lazy to test efficiency of these long expressions (col1 = "x" OR
col1 = "y" OR ...). But in the end I decided just to clone my table
schema into a temp table and populate this with the data. Also, this
overcomes similar custom sort issues.

Cheers,
-Mike
 

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