Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Recursive Single Table Tree only showing top levels in 2.5.6
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
amsimmon



Joined: 31 Mar 2006
Posts: 13

PostPosted: Thu Aug 10, 2006 3:35 pm    Post subject: Recursive Single Table Tree only showing top levels in 2.5.6 Reply with quote

I'm upgrading from VirtualTree 2.5.3 to 2.5.6 so I'm changing our code to use the new DataRow binding from the old DataRowView binding. I'm building with .NET 2.0 in VS2005. The code worked perfectly before I upgraded the control. We have a single table with id and parent id fields establishing a recursive tree structure.

My code to set the datasource is:

Code:

DataView view = _bundleDS.ProductBundleStructure.DefaultView;
view.RowFilter = "ParentProductBundleStructureId IS NULL";
bundleTree.DataSource = view;


The tree only displays the root and it's first level children. All the children below that first level down are not displayed.

If I comment out the RowFilter line that filters to the root item, all the children show up in the main tree. But, then all the children are also displayed as their own root level node alongside the main tree(which is why the filter was there before).

Looks like the binding code for this case has changed. How should I change my code to make it work as expected?

Thanks,
Andy Simmons
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Aug 10, 2006 10:32 pm    Post subject: Reply with quote

Hi Andy, I've just checked a test project that we have with a recursive database definition (like what you describe below). It is working OK with version 2.5.6. I will email you a copy of this project. If you still can't figure out what the issue is with your application if you could email us a sample project that would help alot.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
amsimmon



Joined: 31 Mar 2006
Posts: 13

PostPosted: Fri Aug 11, 2006 8:41 pm    Post subject: Reply with quote

I didn't get your email because the site still had my old email before the merger. Could you please resend the test project to my new address on the site? I'm sure it will be very helpful.

Thanks!
Back to top
View user's profile Send private message
amsimmon



Joined: 31 Mar 2006
Posts: 13

PostPosted: Fri Aug 11, 2006 9:20 pm    Post subject: IGNORE LAST POST - figured it out Reply with quote

Ok, I figured it out. I'd guess your test code doesn't use the DataTable's DefaultView as the view that it passes in. Mine did. Setting the RowFilter on that makes the control only display the top two levels.

I changed my code to create a new view on the table with the Parent Is NULL rowfilter instead of using the DefaultView and it works fine.

If I add the line below to my code, even though I'm not passing the DefaultView as the DataSource of the VirtualTree, the children rows disappear.

Code:

_bundleDS.ProductBundleStructure.DefaultView.RowFilter = "ParentProductBundleStructureId IS NULL";           


So in summary, it looks like the VirtualTree code must be using the DefaultView of the DataTable under the view and not checking the RowFilter on it, which it wasn't doing in 2.5.3. Either way, I have a workaround so I'm good.

Thanks !
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Aug 11, 2006 11:46 pm    Post subject: Reply with quote

I have sent the sample project to your new address. We will check out whether using a filter on the DefaultView should be causing this issue.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Aug 17, 2006 1:55 am    Post subject: Reply with quote

I've done some research on this. Virtual Tree uses the DefaultView for the table internally to create the ChildViews (containing the children for each row). Hence you cannot set the Filter on the DefaultView and need to create a new View as you have found.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Wed Sep 06, 2006 8:30 am    Post subject: Reply with quote

Hi,
I am currently evaluating VirtualTree. I am especially interested in how recursive data structures are used with VirtualTree and would be very happy if you could also send me your sample project for this issue.

Thanks a lot

Dirk Weber
Back to top
dweber



Joined: 06 Sep 2006
Posts: 6

PostPosted: Wed Sep 06, 2006 8:31 am    Post subject: Reply with quote

uups,
forgot to login before sending my message.
You can find my email in my profile.

Thanks again

Dirk Weber
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Wed Sep 06, 2006 11:42 am    Post subject: Reply with quote

We've emailed you the sample project.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dweber



Joined: 06 Sep 2006
Posts: 6

PostPosted: Thu Sep 07, 2006 1:22 pm    Post subject: Reply with quote

Thank you very much for the sample project. Your response time is amazing Smile

I had a look into the sample and so far I think I understood it. Unfortunately in my project I am using objects instead of a dataview. I tried to transfer your sample to my objects but had no luck so far. Either I get only the root object and the first level of children but nothing underneath or I get all the objects with the underlying children on the same (top) level.
I think I am missing some understanding on how to setup the tree correctly and hope to get your support.

I want to show a tree with different topics and cardboxes that are linked 1:N to these topics. Additionally Topics are recursively linked.
Here's the result I want to achieve:

topic0
|
--topic 1
| |
| --topic3
| | |
| | --cardbox1
| | |
| | --cardbox2
| |
| --topic4
| |
| --topic5
| | |
| | --cardbox3
| | |
| | --topic6
| | |
| | --cardbox4
|
--topic2
| |
| --topic7
| | |
| | --cardbox5
| | |
| | --cardbox6

Here's the class definition of Topic and Cardbox

Code:

   public class Topic
    {
        private Guid m_TopicID;
        private Guid? m_ParentID;
        private string m_Name;
        private List<Topic> m_Topics = new List<Topic>(); //Liste der Child-Topics
         
        public Topic()
        {
            m_TopicID = Guid.Empty;
            m_ParentID = Guid.Empty;
            m_Name = "";
            m_Topics = null;
        }

        public Guid TopicID
        {
            get { return m_TopicID; }
            set { m_TopicID = value; }
        }

        public Guid? ParentID
        {
            get { return m_ParentID; }
            set { m_ParentID = value; }
        }

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        public List<Topic> Topics
        {
            get { return m_Topics; }
            set { m_Topics = value; }
        }
    }

    public class Cardbox
    {
        private Guid m_CardboxID;
        private Guid? m_TopicID;
        private string m_Name;

        public Cardbox()
        {
            m_TopicID = Guid.Empty;
            m_Name = "";
        }
       
        public Guid CardboxID
        {
            get { return m_CardboxID; }
            set { m_CardboxID = value; }
        }
       
        public Guid? TopicID
        {
            get { return m_TopicID; }
            set { m_TopicID = value; }
        }
       
        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
    }

To keep things simple I would like to start with the topics only and solve the recursion problem before I step over to my cardboxes. I created a method within my business layer that returns a list of Topics:

Code:

        public List<Topic> Topics
        {
            get
            {
                return new List<Topic>(GetTopics());
            }
        }

        private Topic[] GetTopics()
        {
            //populate a dataset from database           
       allDataSet = LCardDataSet.GetAllDatabase();

            List<Topic> topics = new List<Topic>();
            List<Topic> childTopics = new List<Topic>();
            Topic topic = new Topic();

            foreach (LCardDataSet.TopicTableRow row in allDataSet.TopicTable.Rows)
            {
                //convert dataRow into topicObject
      topic = ConvertDatarowToTopicObject(row);

      //Get all child topicObjects for current TopicID
                childTopics = GetTopicsByParentID(topic.TopicID);

                if (childTopics != null && childTopics.Count > 0)
                {
                    topic.Topics = childTopics;
                }
                topics.Add(topic);
            }
           
            return topics.ToArray();
        }

In my presentation layer I connect VirtualTree to the list
Code:

            topicTree.DataSource = topicLogic.Topics;


In the Tree Editor I set Topic as TypeName and Topics as ChildProperty and ParentID as ParentProperty.

The result is, I get all the objects on the top level, each of the with one level of the underlying children.

I assume it has something to do with the way I populate my list of Topics, but I am not sure if this is the problem.

I hope you can help

Dirk Weber
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Sep 07, 2006 10:17 pm    Post subject: Reply with quote

Take a look at the SimpleTree Sample Project - it does exactly what you want. It uses a single class (called "Part") which can have other Part objects as children. Generally in this case you would then set your topmost (root) object as the DataSource.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dweber



Joined: 06 Sep 2006
Posts: 6

PostPosted: Fri Sep 08, 2006 11:56 am    Post subject: Reply with quote

Thanks for your help. I found the problem in my code. When setting up the object list for VirtualTree I didn't reference all child objects correctly and so the tree was only shown until the first child level.

As soon as I built my list with a recursive method with correct object references and adjusted my object class it worked.

I provide the code how I populated my object list, in case somebody steps into the same trap Smile

Code:

public class Topic
{
   private Guid m_TopicID;
   private Guid? m_ParentID;
   private string m_Name;
   private List<Topic> m_ChildTopics = new List<Topic>(); //List of Child-Topics
   private Topic m_ParentTopic;
   private List<Cardbox> m_ChildCardboxes = new List<Cardbox>(); // List of Child-Cardboxes

   public Topic()
   {
       m_TopicID = Guid.Empty;
       m_ParentID = Guid.Empty;
       m_Name = "";
       m_ChildTopics = new List<Topic>();
       m_ParentTopic = null;
       m_ChildCardboxes = new List<Cardbox>();
   }

   public Guid TopicID
   {
       get { return m_TopicID; }
       set { m_TopicID = value; }
   }

   public Guid? ParentID
   {
       get { return m_ParentID; }
       set { m_ParentID = value; }
   }

   public string Name
   {
       get { return m_Name; }
       set { m_Name = value; }
   }

   public List<Topic> ChildTopics
   {
       get { return m_ChildTopics; }
       set { m_ChildTopics = value; }
   }

   public Topic ParentTopic
   {
       get { return m_ParentTopic; }
       set { m_ParentTopic = value; }
   }
   
   ...

   public Topic GetTopicObjectTree()
   {
      Topic root = new Topic();
        //get rootobject of tree first - in this case rootobject can be found by empty GUID 
   root = GetTopicByTopicID(Guid.Empty);
        return (BuildTopicTree(root));
   }

   // recursive method to populate object list
   private Topic BuildTopicTree(Topic _t)
   {
       List<Topic> childTopics = new List<Topic>();

       childTopics = GetTopicsByParentID(_t.TopicID);
       if (childTopics != null && childTopics.Count > 0)
       {
           foreach (Topic topic in childTopics)
           {
               if (topic.TopicID != Guid.Empty)
               {
                   _t.ChildTopics.Add(topic);
                   topic.ParentTopic = _t;

                   //Recursion
         BuildTopicTree(topic);
               }
           }
       }
       return _t;
   }

   ...

}


And from my presentation layer I just call

Code:

topicTree.DataSource = topicLogic.GetTopicObjectTree();



It's simple - as soon as I knew what to do Wink

Dirk Weber
Back to top
View user's profile Send private message
dweber



Joined: 06 Sep 2006
Posts: 6

PostPosted: Fri Sep 08, 2006 12:15 pm    Post subject: Reply with quote

after having solved my basic problem on bringing my recursive data into VirtualTree I now face another issue.

As mentioned in a former post I also want to show a second object type 'cardbox' within the same tree that is 0..N related to the 'topic' object.

topic0
|
--topic 1
| |
| --topic3
| | |
| | --cardbox1
| | |
| | --cardbox2
| |
| --topic4
| |
| --topic5
| | |
| | --cardbox3


I included a new property in my topic class that holds all child cardboxes and filled it. Furthermore I added a new object binding to virtual tree of type 'cardbox'.

And here comes my problem:
As ChildProperty and ParentProperty of Object 'Topic' are already filled because of the recursive structure I cannot put in a child connection to the second object type. The result is, that only the topics are shown in the tree but no cardboxes.

How can I get around this?

I hope I made my problem clear enough (sorry for my English).
If this problem can be solved VirtualTree is a definite buy and I will use it in my current project.

Dirk
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Sep 08, 2006 9:51 pm    Post subject: Reply with quote

There are several ways you can do this. One way is to add a property to your Topic class that returns all the children (ie both Topics and Cardbox) of the given node. This would need to be an untyped collection. You can then bind to this property.

Another way is to handle the GetChildren event programmatically and return the children required for each node. See the section in the help on Programmatic binding.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
dweber



Joined: 06 Sep 2006
Posts: 6

PostPosted: Sat Sep 09, 2006 6:04 am    Post subject: Reply with quote

Thanks. I will try this.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group