radtreeview image from database

8 posts, 0 answers
  1. behnam
    behnam avatar
    3 posts
    Member since:
    Jan 2018

    Posted 10 Jan 2018 Link to this post

    Hello
    I'm gonna read RadTreeView data from DataBase, where ninety are indefinitely subNode
    Please guide
  2. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 10 Jan 2018 Link to this post

    Hello, Behnam,   

    Thank you for writing.  

    According to the provided brief description, I suppose that you are trying to populate RadTreeView with large data coming from the database. For this case, it would be suitable to use the load on demand approach. Thus, data won't be loaded all at once. The following help article is quite useful on this topic: https://docs.telerik.com/devtools/winforms/treeview/data-binding/load-on-demand

    If it is not the exact case, please specify in details what is the exact goal that you are trying to achieve. Thus, we would be able to think about a suitable solution and assist you further. 

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. behnam
    behnam avatar
    3 posts
    Member since:
    Jan 2018

    Posted 13 Jan 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hello

    Please Guide me...

    picture attach...

    Thankful

  4. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 15 Jan 2018 Link to this post

    Hello, Behnam,  

    Thank you for writing back. 

    The provided screenshot is greatly appreciated. In order to assign a specific image to RadTreeView nodes, it is suitable to use the NodeFormatting event. You can find below a sample code snippet demonstrating how to populate RadTreeView with data and add the relevant image to the node: 
    private void RadForm1_Load(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("ParentId", typeof(int));
        dt.Columns.Add("ImageIcon", typeof(int));
     
        dt.Rows.Add(1, "Item1", 0, 0);
        dt.Rows.Add(2, "Item2", 0, 0);
        dt.Rows.Add(3, "Item3", 2, 1);
        dt.Rows.Add(4, "Item4", 2, 1);
        dt.Rows.Add(5, "Item5", 4, 0);
     
        this.radTreeView1.NodeFormatting += radTreeView1_NodeFormatting;
         
        this.radTreeView1.DisplayMember = "Name";
        this.radTreeView1.ParentMember = "ParentId";
        this.radTreeView1.ChildMember = "Id";
       
        this.radTreeView1.DataSource = dt;
    }
     
    private void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
    {
        DataRowView rowView = e.Node.DataBoundItem as DataRowView;
        if (rowView!=null)
        {
            if ((int)rowView.Row["ImageIcon"] == 0)
            {
                e.NodeElement.Image = Properties.Resources.check;
            }
            else
            {
                e.NodeElement.Image = Properties.Resources.remove;
            }
        }
    }



    I hope this information helps. If you have any additional questions, please let me know. 

     Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. behnam
    behnam avatar
    3 posts
    Member since:
    Jan 2018

    Posted 03 Feb 2018 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Thanks for your support and responsiveness,

    But I can not find "NodeFormatting"

    not Event NodeFormatting

    vs 2012 and framework3.5

    -private void radTreeView1_NodeFormatting-

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 05 Feb 2018 Link to this post

    Hello, Behnam,  

    Thank you for writing back. 

    The NodeFormatting event is at RadTreeView level. I have attached my sample project for your reference. 

    I hope this information helps.

      Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. José Miguel
    José Miguel avatar
    1 posts
    Member since:
    Mar 2019

    Posted 23 Apr 2019 Link to this post

    Good afternoon, you could help me or an explanation because when I resize the image it causes an overload error, example:

    private void treeView_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
            {
                if ((e.Node.DataBoundItem as object).Imagen != null)
                {

        //With the following code if it gives an overload error
                    var imageNew = (Image)new Bitmap((e.Node.DataBoundItem as object).Imagen, new Size(8,8));
                    e.Node.Image = imageNew;

    //With the following code does not give error
                    e.Node.Image = (e.Node.DataBoundItem as object).Imagen;
                }
            }

  8. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 24 Apr 2019 Link to this post

    Hello, José Miguel,    

    Please have in mind that the NodeFormatting event is constantly firing while you are scrolling, filtering the nodes or hovering a certain node. This event is purposed to introduce the correct style of a visual node element considering the current element's state. Creating a brand new image in the NodeFormatting event is not a suitable approach because a lot of images will be created with each firing of the event. 

    The possible solution that I can suggest is to create the necessary images in advance. You can store the images in an appropriate collection storing the unique identifier of the node and the respective image. Then, just use the already stored images in the NodeFormatting event.
     
    I hope this information helps.

    Regards,
    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top