views:

42

answers:

1

I've got a table which has the usual ParentID, ChildID as it's first two columns in a self-referencing tree data structure.

My issue is that when I pull this out and use the following code:

DataSet set = DA.GetNewCategories();
        set.Relations.Add(
            new DataRelation("parentChildCategories", set.Tables[0].Columns["CategoryParentID"], set.Tables[0].Columns["CategoryID"])
            );
        StringBuilder buildXml = new StringBuilder();
        StringWriter writer = new StringWriter(buildXml);
        set.WriteXml(writer);
        TreeView2.DataSource = new HierarchicalDataSet(set, "CategoryID", "CategoryParentID");
        TreeView2.DataBind();

I get the error:

These columns don't currently have unique values

I believe this is because my data has children with multiple parent nodes. This is fine for my application - I don't mind if one row of data is rendered in multiple nodes of my TreeView.

Could someone shed light on this please? It doesn't seem unreasonable to have a DataSet render XML which has nodes appearing in multiple places, but I can't figure out how to do it.

Thanks,

Matt.

A: 

You could have a third column in your table that has ( parentID +"_"+ categoryId ) in it and than use that column in the HierarchicalDataSet. This would be unique through out your tree

And also you need to the same for the parent Ids so that they match match the category ids

cellik
Marking this as the answer, as I've used this solution before, however in this case the data was too dirty for it to work.
Matt W