Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: FilterNodeControl  (Read 135 times)

0 Members and 1 Guest are viewing this topic.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
FilterNodeControl
« on: January 15, 2012, 11:35:32 AM »
Hi (again) - I am still beating on this dynamic filtering.  I really need to try and get this to work as it is the best way for some of my data.

Can you tell me what is wrong with this code?  The tree is set to dynamic filtering and breakpoints show me that the visibility is returned as .Visible for each of the 3 images and the bitmaps are correctly supplied when requestd in the ValueGet.  There are no other nodes in the tree.  On screen I get nothing except the lines from .Root to the nodes.

Code: [Select]
class TestNodeB : Node
    {
        public static NodeImage TreeImage = new NodeImage();
        public static NodeImage StatusImage = new NodeImage();
        public static NodeImage DescriptionImage = new NodeImage();

        private static NodeControl[] temp = { TreeImage, StatusImage, DescriptionImage, };
        public static List<NodeControl> Controls = new List<NodeControl>(temp);

        public TestNodeB(Node pParentNode)
        {
            Text = "Test Node";
            AttachTo(pParentNode);

            if (!pParentNode.Treeview.NodeControls.Contains(TreeImage))
            {
                TreeImage.AttachTo(pParentNode.Treeview);
                TreeImage.ColumnId = 0;
                TreeImage.VirtualMode = true;

                StatusImage.AttachTo(pParentNode.Treeview);
                StatusImage.ColumnId = 3;
                StatusImage.VirtualMode = true;

                DescriptionImage.AttachTo(pParentNode.Treeview);
                DescriptionImage.ColumnId = 5;
                DescriptionImage.VirtualMode = true;
            }

            this.Treeview.FilterNodeControl += FilterNodeControl;
            this.Treeview.NodeControlValueGet += NodeControlValueGet;
        }

        bool NodeControlValueGet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                if (Controls.Contains(pArgs.NodeControl))
                {
                    if (pArgs.NodeControl == TreeImage)
                    {
                        pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["image_6"];
                        return true;
                    }
                    else if (pArgs.NodeControl == StatusImage)
                    {
                        pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["image_7"];
                        return true;
                    }
                    else if (pArgs.NodeControl == DescriptionImage)
                    {
                        pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["image_8"];
                        return true;
                    }
                }
                else
                {
                    return true;
                }
            }

            return false;
        }

        public void FilterNodeControl(FlexibleTreeView pTreeview, FilterNodeControlEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                if (Controls.Contains(pArgs.NodeControl))
                {
                    pArgs.ControlVisibility = eNodeControlVisibility.Visible;
                }
                else
                {
                    pArgs.ControlVisibility = eNodeControlVisibility.Hidden;
                }
            }
        }
    }

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: FilterNodeControl
« Reply #1 on: January 16, 2012, 01:43:33 AM »
Your code is correct except that you need to move the tree event handlers attachments (this.Treeview.FilterNodeControl += FilterNodeControl, ...) into 'if (!pParentNode.Treeview.NodeControls.Contains(TreeImage))' block to execute only once.
Please check the attached project that shows three images as you need (expand the root node, your node is inside).

You may not see anything if your columns Ids aren`t 0,3,5!

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: FilterNodeControl
« Reply #2 on: January 16, 2012, 03:23:21 AM »
Hi Ruslan

I had already tried adding the event handlers in where you said "just to see what happened".  As expected it handles only the first node created and not all of them.  So the handlers should be added for all.

I have tried your project.  Yes, it works for one node but not for more than one....change your OnLoad to add more than one and you will see that only the first node "ch" paints.

Code: [Select]
    protected override void OnLoad(EventArgs e)
    {
      var node = new Node();
      node.AttachTo(tree);

      var ch = new TestNodeB(node);
      var ch1 = new TestNodeB(node);
      var ch2 = new TestNodeB(node);
    }

Now move the event handlers so that they are added for all nodes and you will see that only the last added ("ch3") paints.

Code: [Select]
    public TestNodeB(Node pParentNode)
    {
      Text = "Test Node";
      AttachTo(pParentNode);

      if (!pParentNode.Treeview.NodeControls.Contains(TreeImage))
      {
        TreeImage.AttachTo(pParentNode.Treeview);
        TreeImage.ColumnId = 0;
        TreeImage.VirtualMode = true;

        StatusImage.AttachTo(pParentNode.Treeview);
        StatusImage.ColumnId = 3;
        StatusImage.VirtualMode = true;

        DescriptionImage.AttachTo(pParentNode.Treeview);
        DescriptionImage.ColumnId = 5;
        DescriptionImage.VirtualMode = true;

      }

      this.Treeview.FilterNodeControl += FilterNodeControl;
      this.Treeview.NodeControlValueGet += NodeControlValueGet;

    }

I appreciate your continued assistance in solving this simple problem and much appreciate the sample project.

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: FilterNodeControl
« Reply #3 on: January 16, 2012, 02:47:53 PM »
I`ve updated the sample project. Now there`re 3 nodes (root + 2 children) and all show icons dynamically. Treeview event handlers was moved out of node code to speed up processing of the tree with many nodes. All nodes shows the same list of node controls. If you need to show different node controls for every node please fix TestNodeB.IsNodeControlVisible code.
« Last Edit: February 26, 2012, 10:12:06 AM by Ruslan »

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: FilterNodeControl
« Reply #4 on: January 16, 2012, 03:34:41 PM »
Thank you.

May I ask if this is the intended method or a work around?  It seems a work around.  It appears straightforward to implement and expand upon but it seems that this is not the intended code interface.

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: FilterNodeControl
« Reply #5 on: January 17, 2012, 02:15:38 PM »
That`s how Flexible TreeView suggested to use in this case.
 

Copyright © 2006-2012 ARMSoft. All rights reserved.