Get All Value Node When Use Node Formatting

3 posts, 0 answers
  1. Mehdi
    Mehdi avatar
    2 posts
    Member since:
    Sep 2013

    Posted 25 Sep 2013 Link to this post

    Hi
    I want Change Node ForeColor In Node Formatting By Check Node Value. But I Get Value For Root Node Only.
    Let Me Know How Can I Get All Node Value In Node Formatting PLS

    TNXXXXXXXXXXXXX

    private void RadTreeView1NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
            {
                try
                {
                    if (BSGroupRoleAccess.Cast<RoleAccess>().Any(x=>x.ID.ToString()==e.Node.Value.ToString()))
                    {
                        ........
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
  2. Mehdi
    Mehdi avatar
    2 posts
    Member since:
    Sep 2013

    Posted 26 Sep 2013 Link to this post

    When I Set "Parrent Member , Child Member and DataSource" In Code (OnLoadEvent) Everything Is Fine, But When I Use TreeView Property Builder I Get Root Value Only 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 30 Sep 2013 Link to this post

    Hello Mehdi,

    Thank you for contacting Telerik Support.

    When you populate RadTreeNode with data at design-time, its nodes have only Text, but no Value is available (please, see the attached picture DesignTimeNodeTextValue.png). When you populate with data at run-time using DataSource property, RadTreeView nodes are initialized with both Text and Value. Please, see the following code snippet, demonstrating how to assign value of each node if you populate the tree view at design-time:
    public Form1()
    {
        InitializeComponent();
     
        //RadTreeView populated at design-time
        foreach (RadTreeNode node in radTreeView1.Nodes)
        {
            InitializeValue(node);              
        }
     
        radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
     
        //RadTreeView populated at run-time
        List<Product> products = new List<Product>();
        products.Add(new Product(567, "Bicycle", 5));
        products.Add(new Product(456, "Car", 5000));
        products.Add(new Product(789, "Bike", 1500));
        List<Category> categories = new List<Category>();
        categories.Add(new Category("Bikes", products));
        categories.Add(new Category("Accessories", null));
        categories.Add(new Category("Clothing", null));
        radTreeView2.DataSource = categories;
        radTreeView2.DisplayMember = "Name\\Description";
        radTreeView2.ChildMember = "Categories\\Products";   
     
        radTreeView2.NodeFormatting += radTreeView2_NodeFormatting;
    }
     
    private void InitializeValue(RadTreeNode node)
    {
        node.Value = node.Text;
        if (node.Nodes.Count > 0)
        {
            foreach (RadTreeNode childNode in node.Nodes)
            {
                InitializeValue(childNode);              
            }
        }
    }
     
    private void radTreeView1_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
    {
        if (e.Node.Value != null && e.Node.Value.ToString().Contains("1"))
        {
            e.Node.ForeColor = Color.Fuchsia;
        }
    }
     
    private void radTreeView2_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
    {
        if (e.Node.Value.ToString().Contains("e"))
        {
            e.Node.ForeColor = Color.Red;
        }
    }
     
    public class Product
    {
        private int _id;
        private string _description;
        private float _price;
     
        public int ID
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
            }
        }
     
        public string Description
        {
            get
            {
                return _description;
            }
            set
            {
                _description = value;
            }
        }
     
        public float Price
        {
            get
            {
                return _price;
            }
            set
            {
                _price = value;
            }
        }
     
        public Product(int id, string description, float price)
        {
            _id = id;
            _description = description;
            _price = price;
        }
    }
     
    public class Category
    {
        public Category(string name, List<Product> products)
        {
            _name = name;
            _products = products;
        }
     
        private List<Product> _products;
        private string _name;
     
        public string Name
        {
            get
            {
                return _name;
            }
            set
            {
                _name = value;
            }
        }
     
        public List<Product> Products
        {
            get
            {
                return _products;
            }
            set
            {
                _products = value;
            }
        }
    }

    I hope this information helps. Should you have further questions, I would be glad to help.

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top