Filter on Parent-child relation??

M

mathieu

Hello, here's my problem..

I have a dataset composed of 5 or so datatable composed of the
following columns

Columns.AddRange(new DataColumn[]
{
new DataColumn("Id", System.Type.GetType("System.Int32")),
new DataColumn("Lib", System.Type.GetType("System.String")),
new DataColumn("ParentId", System.Type.GetType("System.Int32"))}
);

Each datatable is in a relation Parent-Child as follow:

Relations.Add(Tables[i-1].Columns["Id"],
Tables.Columns["ParentId"]);

Now, I want to filter tables on the row Id or Lib.
But if for example i find a lib (or id) corresponding in let's say
table 4, I must show the parent of that row till i'm back to the top.
To do so i created a hidden column called "Flag" and update it
manually when a search occur. I begin by searchin the last table and
set Flag=1 to all rows returned. Then goes to the level before and
search again. But this time my filter will be
"Sum(Child.Flag)>0 OR " + MyFilter
This way i get the rows in the current level that matches the search
criteria and also the ones that don't but have a child that does.

Now when i'm done i create a new dataview for each table like this

DataView dvSearch = new DataView(myTable);
dvSearch.RowFilter = "Flag=1";

After i bind the first table dataview (the search one)to a datagrid.

dataGrid1.DataSource = DataViewSearchOfFirstTable;

The problem is that the DataGrid show all the table rows and not only
the filtered one? what is wrong ? I'm not used to work with DataTable
and DataView Should i use instead a DataViewManager?

ps: For sure the Flag is correctly set to 1 on rows matching the
search criteria and the parent.

Thanks
Mathieu
 
G

Guest

Hello Matieu

It seems we have been struggling on the very same problem, I was digging
arround to find out if the flag was the only way out to a parent filtering.
Well at least i'm not the only guy with this idea...
About your problem, I had the same issue, and it seems that if you bind
to your control the datatable object it works, and if you bind a dataset and
informs the DataMember it doesnt work... I dont know why, maybe a bug? the
point is:
USE
grid.DataSet=myDataSet.Tables["Customer"]
DONT USE:
grid.DataSet=myDataSet
grid.DataMember="Customer"

Its a bit late since your post, but I hope to help you, or others...

By the way, have anyone found another solution to parent filtering???

Fábio.
 

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