Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: NodeWithControl Images  (Read 79 times)

0 Members and 1 Guest are viewing this topic.

mark.robertson

  • Customer
  • Newbie
  • *
  • Offline Offline
  • Posts: 29
NodeWithControl Images
« on: January 09, 2012, 02:13:36 PM »
Hi - is there a standard method for naming image properties so that you get the appropriate one?

I have different node types inherited from NodeWithControl.  In these new classes I add this to show the image (your code access Image as a DataField I think as Image is not a property of NodeWithControl):

Code: [Select]
public class MyNodeWithControlAndImage : NodeWithControl
{
        public Bitmap Image
        {
            get {
                if (Expanded)
                {
                    return ExpandedImage;
                }
                else
                {
                    return m_Image;
                }
            }
            set { m_Image = value; }
        }

        public Bitmap ExpandedImage
        {
            get { return m_ExpandedImage; }
            set { m_ExpandedImage = value; }
        }

        public MyNodeWithControlAndImage()
        {
        }
}


I just wonder if you have a standard method for the different state images per node?  For example, do you have standardised DataFieldNames for the known different images (expanded, normal, selected, etc)? 

Or do I code using the Image property as I have done (adding an ImageList or multiple fixed properties or whatever I decide).  This is not a problem....am just seeking advice.

Thanks

Ruslan

  • Flexible TreeView Team
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 569
Re: NodeWithControl Images
« Reply #1 on: January 09, 2012, 02:54:01 PM »
Hi,

You have two ways to go here:
1) Use tree.StateImages collection of images to define icons for expanded and collapsed nodes with children:
Code: [Select]
tree.StateImages.GroupCollapsed = myIconForCollapsedNode;
Note that you have an option to define icons only for expanded or collapsed nodes disregarding of other node`s parameters (under the mouse cursor, etc.).

2) Other way is to virtualize bound property, i.e. supply the bound property value dynamically in run-time:
Code: [Select]
var img = new NodeImage();
img.AttachTo(tree);
img.DataFieldName = "myField";
img.VirtualMode = true;
var tb = new NodeTextBox();
tb.AttachTo(tree);

var node = new Node("test");
node.AttachTo(tree);

tree.NodeControlValueGet += tree_NodeControlValueGet;

bool tree_NodeControlValueGet(FlexibleTreeView pTreeview, NodeControlValueEventArgs pArgs)
{
  if (pArgs.FieldName == "myField")
  {
    pArgs.Value = pArgs.Node.IsHot ? Resources.HotIcon : Resources.GeneralIcon;
    return true;
  }
  return false;
}

Key code pieces here are img.VirtualMode = true and tree_NodeControlValueGet(...) where you return images according to the node state.

If you choose second approach, please don`t return icons right from your resources instance (Resources.HotIcon)! Cache them and then return because it will slow down your tree because of frequent calls.
 

Copyright © 2006-2012 ARMSoft. All rights reserved.