Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: NodeControl binding  (Read 305 times)

0 Members and 1 Guest are viewing this topic.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
NodeControl binding
« on: January 13, 2012, 11:41:25 AM »
Hi

Working my way through getting familiar. 

In my test app I am adding two of these NodeWithComboBox, each to show in column 1.  Both are attached to the same parent node.  Problem is I am getting two combo per node's column not just the one (the ComboBox object).  I thought my visibility management within this sub-class would stop this happening....clearly it is not working.

Thanks for helping in advance.


Code: [Select]
    class NodeWithComboBox : BasicNode
    {
        public NodeComboBox ComboBox;
        public int SelectedIndex = -1;

        public NodeWithComboBox(Node pParentNode, int column, string title, string[] items, string value)
        {
            Text = title;

            ComboBox = new NodeComboBox();
            ComboBox.DataFieldName = "SelectedIndex";
            ComboBox.EditStartMode = eEditStartMode.ClickOnSelected;
            ComboBox.Editable = true;
            ComboBox.InteractiveDropDownItems = true;
            ComboBox.DropDownItems = items;
            ComboBox.ColumnId = column;
            ComboBox.VirtualMode = true;

            Value = value;
            AttachTo(pParentNode);
            ComboBox.AttachTo(pParentNode.Treeview);
            this.Treeview.NodeComboBoxGetItems += NodeComboBoxGetItems;
            this.Treeview.FilterNodeControl += FilterNodeControl;
        }

        public string Value
        {
            get {
                if (SelectedIndex >= ComboBox.DropDownItems.Count)
                {
                    return "";
                }
                else
                {
                    return ComboBox.DropDownItems[SelectedIndex].ToString();
                }
            }

            set {
                int ix = 0;
                foreach (Object str in ComboBox.DropDownItems)
                {
                    if (str.ToString() == value)
                    {
                        SelectedIndex = ix;
                        break;
                    }
                    ix++;
                }
                SelectedIndex = -1;
            }
        }

        public new void FilterNodeControl(FlexibleTreeView pTreeview, FilterNodeControlEventArgs pArgs)
        {
            if (pArgs.NodeControl == this.ComboBox)
            {
                pArgs.ControlVisibility = eNodeControlVisibility.Visible;
            }
        }

        private void NodeComboBoxGetItems(FlexibleTreeView pTreeview, NodeComboBoxGetItemsEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Items = ComboBox.DropDownItems;
            }
        }
    }

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #1 on: January 13, 2012, 01:00:10 PM »
Hi - I know the last method was inefficient (lots of controls created) and have been working at this.  I have changed my constructor for the sub-class node to only create a new NodeComboBox if there is not one registered for this column.  Code is below and I do not get the double controls now.

My question is ..... is there a better/more elegant method for doing this with core tree classes/objects?  I really wish to create self-contained node classes that handle everything themselves and do not wish to mix node level code with code that has to create a tree and know what the nodes want (e.g. I know I could create every control type in every column or pre-plan and create what may be required in every column).

Thanks.

Code: [Select]
    class NodeWithComboBox : BasicNode
    {
        public int SelectedIndex = -1;
        public string[] Items = { };
        public int ColumnID = 0;
        public Boolean Editable = false;

        public NodeWithComboBox(Node pParentNode, int column, string title, string[] items, string value)
        {
            Text = title;

            Boolean add = true;
            foreach (NodeControl nc in pParentNode.Treeview.NodeControls)
            {
                if ((nc is NodeComboBox) && (nc.ColumnId == column))
                {
                    add = false;
                    break;
                }
            }

            if (add)
            {
                NodeComboBox newBox = new NodeComboBox();
                newBox.DataFieldName = "SelectedIndex";
                newBox.EditStartMode = eEditStartMode.ClickOnSelected;
                newBox.Editable = true;
                newBox.InteractiveDropDownItems = true;
                newBox.ColumnId = column;
                newBox.VirtualMode = true;

                newBox.AttachTo(pParentNode.Treeview);
            }

            ColumnID = column;
            Items = items;
            Value = value;
            AttachTo(pParentNode);
            this.Treeview.NodeComboBoxGetItems += NodeComboBoxGetItems;
            this.Treeview.FilterNodeControl += FilterNodeControl;
        }

        public string Value
        {
            get
            {
                if (SelectedIndex >= Items.Count())
                {
                    return "";
                }
                else
                {
                    return Items[SelectedIndex];
                }
            }

            set
            {
                int ix = 0;
                foreach (string str in Items)
                {
                    if (str == value)
                    {
                        SelectedIndex = ix;
                        break;
                    }
                    ix++;
                }
                SelectedIndex = -1;
            }
        }

        public new void FilterNodeControl(FlexibleTreeView pTreeview, FilterNodeControlEventArgs pArgs)
        {
            if ((pArgs.NodeControl.ColumnId == ColumnID) && (pArgs.NodeControl is NodeComboBox))
            {
                (pArgs.NodeControl as NodeComboBox).Editable = Editable;
                pArgs.ControlVisibility = eNodeControlVisibility.Visible;
            }
        }

        private void NodeComboBoxGetItems(FlexibleTreeView pTreeview, NodeComboBoxGetItemsEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Items = Items;
            }
        }
    }

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #2 on: January 14, 2012, 04:55:22 AM »
Hi

Now I have myself even more confused.

I created a new tree so that no others events were getting in the way.  I then added one of my nodes (as below) which owns it controls and holds them in a List.  I do not get any text or anything drawn and the GetValue event is called only for the Images never for the other controls.

What am I missing?

Thanks

Tree Construction
Code: [Select]
            treeView2 = new TreeViewWithImages();
            treeView2.Parent = this.splitContainer1.Panel1;

            treeView2.Bitmaps = null;
            treeView2.AppendImageList(CommonImageList, CommonImageListNames);

            treeView2.Dock = DockStyle.Fill;
            treeView2.Columns.Clear();
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Options.Column.ShowVertLines = false;
            treeView2.Options.NodeControl.DynamicColumnSpan = true;
            treeView2.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Dynamic;

            BaudRateNode BR2 = new BaudRateNode(treeView2.Root);
            BR2.Text = "BR2";

Node
Code: [Select]
    class BaudRateNode : Node
    {
        public int SelectedIndex = -1;
        //public string[] Items = { };
        //public int ColumnID = 0;
        public Boolean Editable = false;
        public string s_Description = "description";
        public string s_Text = "node";
       

        public NodeImage TreeImage;
        public NodeTextBox TreeText;
        public NodeImage StatusImage;
        public NodeComboBox BaudRate;
        public NodeImage DescriptionImage;
        public NodeTextBox Description;

        List<NodeControl> Controls = new List<NodeControl>();

        public BaudRateNode(Node pParentNode)
        {
            Text = "Baud Rate";
            AttachTo(pParentNode);

            TreeImage = new NodeImage();
            TreeImage.AttachTo(pParentNode.Treeview);
            TreeImage.ColumnId = 3;
            TreeImage.VirtualMode = true;
            TreeImage.FillFreeSpace = true;

            TreeText = new NodeTextBox();
            TreeText.AttachTo(pParentNode.Treeview);
            //TreeText.DataFieldName = "s_Text";
            TreeText.ColumnId = 3;
            TreeText.VirtualMode = true;
            TreeText.FillFreeSpace = true;

            StatusImage = new NodeImage();
            StatusImage.AttachTo(pParentNode.Treeview);
            StatusImage.ColumnId = 4;
            StatusImage.ContentAlign = ContentAlignment.MiddleCenter;
            StatusImage.VirtualMode = true;
            StatusImage.FillFreeSpace = true;

            BaudRate = new NodeComboBox();
            BaudRate.AttachTo(pParentNode.Treeview);
            BaudRate.ColumnId = 5;
            BaudRate.DataFieldName = "SelectedIndex";
            BaudRate.EditStartMode = eEditStartMode.ClickOnSelected;
            BaudRate.Editable = true;
            //BaudRate.InteractiveDropDownItems = true;
            BaudRate.VirtualMode = true;
            BaudRate.FillFreeSpace = true;
            BaudRate.DropDownItems = new string[] { "19200", "38400", "57600" };

            DescriptionImage = new NodeImage();
            DescriptionImage.AttachTo(pParentNode.Treeview);
            DescriptionImage.ColumnId = 6;
            DescriptionImage.ContentAlign = ContentAlignment.MiddleCenter;
            DescriptionImage.VirtualMode = true;
            DescriptionImage.FillFreeSpace = true;

            Description = new NodeTextBox();
            Description.AttachTo(pParentNode.Treeview);
            Description.DataFieldName = "s_Description";
            Description.ColumnId = 6;
            Description.VirtualMode = true;
            Description.FillFreeSpace = true;

            Controls.Add(TreeImage);
            Controls.Add(TreeText);
            Controls.Add(StatusImage);
            Controls.Add(BaudRate);
            Controls.Add(DescriptionImage);
            Controls.Add(Description);

            //ColumnID = column;
            //Value = value;

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

        bool NodeControlValueGet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
        {
            if ((pArgs.Node == this) && Controls.Contains(pArgs.NodeControl))
            {
                if (pArgs.NodeControl == TreeText)
                {
                    pArgs.Value = "test";
                }
                else if (pArgs.NodeControl == BaudRate)
                {
                    pArgs.Value = "19200";
                }
                else if (pArgs.NodeControl == Description)
                {
                    pArgs.Value = "Hello";
                }

                return true;
            }

            return false;
        }

        public string Value
        {
            get
            {
                if ((SelectedIndex < 0) || (SelectedIndex >= BaudRate.DropDownItems.Count))
                {
                    return "";
                }
                else
                {
                    return BaudRate.DropDownItems[SelectedIndex].ToString();
                }
            }

            set
            {
                int ix = 0;
                foreach (string str in BaudRate.DropDownItems)
                {
                    if (str == value)
                    {
                        SelectedIndex = ix;
                        return;
                    }
                    ix++;
                }
                SelectedIndex = -1;
            }
        }

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

        private void NodeComboBoxGetItems(FlexibleTreeView pTreeview, NodeComboBoxGetItemsEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Items = BaudRate.DropDownItems;
            }
        }

        private void NodeEditing(FlexibleTreeView pTreeview, NodeEditingEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Cancel = !Editable;
            }
        }
    }

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #3 on: January 14, 2012, 05:26:13 AM »
Hi

Final revision as I am more clear now on what I need solved.  Code is below.
1. I create a tree with columns
2. I create a node which has multiple controls
3. If I put each control in its own column it works
4. if I put two controls in the same column I only get one control - the first control in that column attached to the tree

If you can help me solve this problem (4) then I have a good starting point and can see how to create nodes that manage themselves.

Tree Create
Code: [Select]
            treeView2 = new TreeViewWithImages();
            treeView2.Parent = this.splitContainer1.Panel1;

            treeView2.Bitmaps = null;
            treeView2.AppendImageList(CommonImageList, CommonImageListNames);

            treeView2.Dock = DockStyle.Fill;
            treeView2.Columns.Clear();
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Columns.Add(new ARMSoft.FlexibleTreeView.Column.TreeColumn());
            treeView2.Options.Column.ShowVertLines = false;
            treeView2.Options.NodeControl.DynamicColumnSpan = true;
            treeView2.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Dynamic;

            BaudRateNode BR2 = new BaudRateNode(treeView2.Root);
            BR2.Text = "BR2";

Node
Code: [Select]
    class BaudRateNode : Node
    {
        public int SelectedIndex = -1;
        //public string[] Items = { };
        //public int ColumnID = 0;
        public Boolean Editable = true;
        public string s_Description = "description";
        public string s_Text = "node";
       

        public NodeImage TreeImage;
        public NodeTextBox TreeText;
        public NodeImage StatusImage;
        public NodeComboBox BaudRate;
        public NodeImage DescriptionImage;
        public NodeTextBox Description;

        List<NodeControl> Controls = new List<NodeControl>();

        public BaudRateNode(Node pParentNode)
        {
            Text = "Baud Rate";
            AttachTo(pParentNode);

            TreeImage = new NodeImage();
            TreeImage.AttachTo(pParentNode.Treeview);
            TreeImage.ColumnId = 1;
            TreeImage.VirtualMode = true;
            TreeImage.FillFreeSpace = true;

            TreeText = new NodeTextBox();
            TreeText.AttachTo(pParentNode.Treeview);
            TreeText.ColumnId = 1;
            TreeText.VirtualMode = true;
            TreeText.FillFreeSpace = true;

            StatusImage = new NodeImage();
            StatusImage.AttachTo(pParentNode.Treeview);
            StatusImage.ColumnId = 3;
            StatusImage.ContentAlign = ContentAlignment.MiddleCenter;
            StatusImage.VirtualMode = true;
            StatusImage.FillFreeSpace = true;

            BaudRate = new NodeComboBox();
            BaudRate.AttachTo(pParentNode.Treeview);
            BaudRate.ColumnId = 4;
            //BaudRate.DataFieldName = "SelectedIndex";
            BaudRate.EditStartMode = eEditStartMode.ClickOnSelected;
            BaudRate.Editable = true;
            //BaudRate.InteractiveDropDownItems = true;
            BaudRate.VirtualMode = true;
            BaudRate.FillFreeSpace = true;
            BaudRate.DropDownItems = new string[] { "19200", "38400", "57600" };

            DescriptionImage = new NodeImage();
            DescriptionImage.AttachTo(pParentNode.Treeview);
            DescriptionImage.ColumnId = 5;
            DescriptionImage.ContentAlign = ContentAlignment.MiddleCenter;
            DescriptionImage.VirtualMode = true;
            DescriptionImage.FillFreeSpace = true;

            Description = new NodeTextBox();
            Description.AttachTo(pParentNode.Treeview);
            Description.DataFieldName = "s_Description";
            Description.ColumnId = 6;
            Description.VirtualMode = true;
            Description.FillFreeSpace = true;

            Controls.Add(TreeImage);
            Controls.Add(TreeText);
            Controls.Add(StatusImage);
            Controls.Add(BaudRate);
            Controls.Add(DescriptionImage);
            Controls.Add(Description);

            //ColumnID = column;
            //Value = value;

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

        bool NodeControlValueGet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
        {
            if ((pArgs.Node == this) && Controls.Contains(pArgs.NodeControl))
            {
                if (pArgs.NodeControl == TreeText)
                {
                    pArgs.Value = "test";
                    return true;
                }
                else if (pArgs.NodeControl == BaudRate)
                {
                    pArgs.Value = 0;
                    return true;
                }
                else if (pArgs.NodeControl == Description)
                {
                    pArgs.Value = "Hello";
                    return true;
                }
                else if (pArgs.NodeControl == TreeImage)
                {
                    pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["folder_open"];
                    return true;
                }
                else if (pArgs.NodeControl == StatusImage)
                {
                    pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["folder_open"];
                    return true;
                }
                else if (pArgs.NodeControl == DescriptionImage)
                {
                    pArgs.Value = (pTreeview as TreeViewWithImages).Bitmaps["folder_closed"];
                    return true;
                }
            }

            return false;
        }

        public string Value
        {
            get
            {
                if ((SelectedIndex < 0) || (SelectedIndex >= BaudRate.DropDownItems.Count))
                {
                    return "";
                }
                else
                {
                    return BaudRate.DropDownItems[SelectedIndex].ToString();
                }
            }

            set
            {
                int ix = 0;
                foreach (string str in BaudRate.DropDownItems)
                {
                    if (str == value)
                    {
                        SelectedIndex = ix;
                        return;
                    }
                    ix++;
                }
                SelectedIndex = -1;
            }
        }

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

        private void NodeComboBoxGetItems(FlexibleTreeView pTreeview, NodeComboBoxGetItemsEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Items = BaudRate.DropDownItems;
            }
        }

        private void NodeEditing(FlexibleTreeView pTreeview, NodeEditingEventArgs pArgs)
        {
            if (pArgs.Node == this)
            {
                pArgs.Cancel = !Editable;
            }
        }
    }

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #4 on: January 14, 2012, 08:50:55 AM »
Regarding your last message:
1) don`t mix node controls creation with node logic, it`s very bad practise and may lead to visual issues (multiple of the same node controls appear in the tree because every added node create and add to the treeview new banch of such node controls). Instead, move all logic regarding node controls creation or node controls` events handling from the BaudRateNode`s .ctor to separate class and call this logic only once after creation of the treeview.
2) You see only first node control because you`ve enabled FillFreeSpace for all node controls. When it is enabled, this particular node control fill all available free space within column from his start location to right end, so you won`t see any other controls because this, first, control grabs all available space. To fix it remove FillFreeSpace=true line for all node controls.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #5 on: January 14, 2012, 09:42:15 AM »
Thanks Ruslan - that worked (of course).

I understand the issue of attaching too many controls and do not want to do it this way.  I was just playing trying to understand the tree.

I think the methodology I will implement is to create a manager inside my tree class just as I am doing with a shared set of images.

thanks again

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #6 on: January 14, 2012, 10:41:52 AM »
Quote
I understand the issue of attaching too many controls and do not want to do it this way.  I was just playing trying to understand the tree.

No, no, you didn`t understand me. You can add as many node controls as many you need, BUT adding them from the node ctor will lead you to that you will have as many node controls copies as many nodes you added (that`s why you see duplicated nodecombobox items in your attached screen after adding two children nodes), and that`s not what you need I guess. Node controls are intended to display node`s data in columns and they should be added to the tree only once. And one node control shows some data for ALL nodes in the tree! Think about node controls as about templates, while node acts as a data source for them.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #7 on: January 14, 2012, 11:31:36 AM »
I do understand what happens in the constructor and it is intentional.  I know it has limitations and I only use this in a few node types with only a single or few instances of this type per tree.

I am trying to minimise the creation of controls within each node by using a seperate manager for these created node controls so that it only creates a control in a column if it does not already exist in that column.  A problem with this (that I have still to solve) is the paint order seems to be the order the controls are attached.  So, I cannot add an image then a text if I wish to display image-text in NodeA and text-image in Node B.  I have to (in this example) attached image-text-image to the column and then manage the visibility depending on node type A or B (both show the text but A shows the first image and B the last).

It would be easier if, on a cell (node-column) I could return an NodeControl[] collection or similar so that I may individually control each cell.  Maybe there is a way to do this?

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #8 on: January 14, 2012, 02:12:34 PM »
Code: [Select]
A problem with this (that I have still to solve) is the paint order seems to be the order the controls are attached.  So, I cannot add an image then a text if I wish to display image-text in NodeA and text-image in Node B.  I have to (in this example) attached image-text-image to the column and then manage the visibility depending on node type A or B (both show the text but A shows the first image and B the last).
Correct. That`s the way to go.

Code: [Select]
It would be easier if, on a cell (node-column) I could return an NodeControl[] collection or similar so that I may individually control each cell.  Maybe there is a way to do this?
Returning node controls list for each node is the same way as defining node controls visiblity using tree.NodeControlFilter.
Also, that may be easier for you, you can attach an event handler to the tree.FilterNodeControl event (add this as well: tree.Options.NodeControl.NodeControlFilterMode = eNodeControlFilterMode.Dynamic) and define which node control to show for specific node in run-time with couple of IFs.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #9 on: January 15, 2012, 10:27:53 AM »
Thanks.  I tried a lot of different methods and have settled on trying to implement by creating controls on construction and using static visibility control.  Problem is I think this will not be the best method for me for others parts of the tree (grid of 300 by 300) where I was using dynamic. 

It seems wasteful to create all these controls but I cannot get dynamic control to work and cannot get static declaring and re-use of the same controls to work.  I just always end up with inexplicable results on screen.

I wish there were more examples.  Yes, you document each function and have the sample suite but, really, multiple small example projects would help hugely.

Code: [Select]
public int SelectedIndex = -1;
        private string s_Description = "description";
        private string s_Text = "node";
        private Bitmap bmp_TreeImage;
        private Bitmap bmp_StatusImage;
        private Bitmap bmp_DescriptionImage;

        public NodeImage TreeImage = new NodeImage();
        public NodeTextBox TreeText = new NodeTextBox();
        public NodeImage StatusImage = new NodeImage();
        public NodeComboBox BaudRate = new NodeComboBox();
        public NodeImage DescriptionImage = new NodeImage();
        public NodeTextBox Description = new NodeTextBox();

        public BaudRateNode(Node pParentNode)
        {
            Text = "Baud Rate";
            AttachTo(pParentNode);

            TreeImage.AttachTo(pParentNode.Treeview);
            TreeImage.ColumnId = 0;
            TreeImage.DataFieldName = "bmp_TreeImage";
            bmp_TreeImage = (this.Treeview as TreeViewWithImages).Bitmaps["folder_open"];

            TreeText.AttachTo(pParentNode.Treeview);
            TreeText.ColumnId = 0;
            TreeText.FillFreeSpace = true;

            StatusImage.AttachTo(pParentNode.Treeview);
            StatusImage.ColumnId = 3;
            StatusImage.ContentAlign = ContentAlignment.MiddleCenter;
            StatusImage.FillFreeSpace = true;
            StatusImage.DataFieldName = "bmp_StatusImage";
            bmp_StatusImage = (this.Treeview as TreeViewWithImages).Bitmaps["image_2"];

            BaudRate.AttachTo(pParentNode.Treeview);
            BaudRate.ColumnId = 4;
            BaudRate.EditStartMode = eEditStartMode.ClickOnSelected;
            BaudRate.Editable = true;
            BaudRate.FillFreeSpace = true;
            BaudRate.DropDownItems = new string[] { "19200", "38400", "57600" };

            DescriptionImage.AttachTo(pParentNode.Treeview);
            DescriptionImage.ColumnId = 5;
            DescriptionImage.ContentAlign = ContentAlignment.MiddleCenter;
            DescriptionImage.FillFreeSpace = true;
            DescriptionImage.DataFieldName = "bmp_DescriptionImage";
            bmp_DescriptionImage = (this.Treeview as TreeViewWithImages).Bitmaps["image_3"];

            Description.AttachTo(pParentNode.Treeview);
            Description.DataFieldName = "s_Description";
            Description.ColumnId = 6;
            Description.FillFreeSpace = true;

            this.Treeview.NodeControlFilter[this, TreeImage] = eNodeControlVisibility.VisibleForThisNodeOnly;
            this.Treeview.NodeControlFilter[this, TreeText] = eNodeControlVisibility.VisibleForThisNodeOnly;
            this.Treeview.NodeControlFilter[this, StatusImage] = eNodeControlVisibility.VisibleForThisNodeOnly;
            this.Treeview.NodeControlFilter[this, BaudRate] = eNodeControlVisibility.VisibleForThisNodeOnly;
            this.Treeview.NodeControlFilter[this, DescriptionImage] = eNodeControlVisibility.VisibleForThisNodeOnly;
            this.Treeview.NodeControlFilter[this, Description] = eNodeControlVisibility.VisibleForThisNodeOnly;
        }

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #10 on: January 16, 2012, 02:25:23 PM »
OK, let`s start from scratch. What treeview do you need to get in result?

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #11 on: January 16, 2012, 03:38:43 PM »
Is OK - I am OK now with the dynamic example of the subsequent thread whilst re-using static-declared controls.  And I believe the answers here and on that thread show a method for creating the same effect with .Static node control filtering.

I think having both those as simple downloadable projects may help others.

Thanks for your help - I can now go and implement.

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #12 on: January 17, 2012, 02:18:55 PM »
You are welcome.

Code: [Select]
I think having both those as simple downloadable projects may help others.
We`re working on such samples but as we work in many directions at the same time it is not so fast.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
Re: NodeControl binding
« Reply #13 on: February 23, 2012, 11:57:57 PM »
Hi

I am just getting back to implementing this methodology - I had to park it for a while to work on something else.

As you may recall my objective is new node classes which create and manage themselves.  In the previous examples it was all providing values to your code.  I now need to set values such as changing listbox values and checkboxes.

My code is this:
Code: [Select]
    class RunNode : Node, MyDynamicNodesDataProvider
    {
        static readonly NodeImage _treeImage = new NodeImage();
        static readonly NodeImage _statusImage = new NodeImage();
        static readonly NodeImage _descriptionImage = new NodeImage();
        static readonly NodeCheckBox _checkBox = new NodeCheckBox();
        static readonly List<NodeControl> _controls = new List<NodeControl>(new[] { _treeImage as NodeControl, _statusImage as NodeControl, _descriptionImage as NodeControl, _checkBox as NodeControl, });

        private Boolean _runState = false;

        public RunNode(Node pParentNode)
        {
            Text = "Run";
            CreateNodeControls(pParentNode);
            AttachTo(pParentNode);
        }

        private static void CreateNodeControls(Node pParentNode)
        {
            if (pParentNode.Treeview.NodeControls.Contains(_treeImage))
                return;

            _treeImage.AttachTo(pParentNode.Treeview);
            _treeImage.ColumnId = 0;
            _treeImage.VirtualMode = true;

            _statusImage.AttachTo(pParentNode.Treeview);
            _statusImage.ColumnId = 1;
            _statusImage.VirtualMode = true;

            _checkBox.AttachTo(pParentNode.Treeview);
            _checkBox.ColumnId = 1;
            _checkBox.VirtualMode = true;

            _descriptionImage.AttachTo(pParentNode.Treeview);
            _descriptionImage.ColumnId = 1;
            _descriptionImage.VirtualMode = true;
        }

        public bool IsNodeControlVisible(NodeControl control)
        {
            return _controls.Contains(control);
        }

        public object GetNodeControlValue(NodeControl control)
        {
            if (_controls.Contains(control))
            {
                if (control == _treeImage)
                {
                    return Resources.accept;
                }
                if (control == _statusImage)
                {
                    return Resources.attach;
                }
                if (control == _descriptionImage)
                {
                    return Resources.bug;
                }
                if (control == _checkBox)
                {
                    return _runState;
                }
            }
            return null;
        }
    }

I have this interface def within the namespace:
Code: [Select]
    internal interface MyDynamicNodesDataProvider
    {
        bool IsNodeControlVisible(NodeControl control);
        object GetNodeControlValue(NodeControl control);
    }


I searched the forum but could not find anything on a func like SetNodeControlValue.  Can you let me know the implementation so I can read and write the node control values?

Thanks

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeControl binding
« Reply #14 on: February 24, 2012, 01:19:48 AM »
Mark,

Node controls are bound to a node property so there`s no need in such method. You just change these bound properties and call the tree.FullUpdate method to invalidate treeview. Or you`re talking about some other logic you need to do?
 

Copyright © 2006-2012 ARMSoft. All rights reserved.