This is a migrated thread and some comments may be shown as answers.

radtreeview image from database

7 Answers 305 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
behnam
Top achievements
Rank 1
behnam asked on 10 Jan 2018, 01:10 PM
Hello
I'm gonna read RadTreeView data from DataBase, where ninety are indefinitely subNode
Please guide

7 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Jan 2018, 01:24 PM
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.
0
behnam
Top achievements
Rank 1
answered on 13 Jan 2018, 06:12 AM

Hello

Please Guide me...

picture attach...

Thankful

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 15 Jan 2018, 12:23 PM
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 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.
0
behnam
Top achievements
Rank 1
answered on 03 Feb 2018, 07:34 AM

Thanks for your support and responsiveness,

But I can not find "NodeFormatting"

not Event NodeFormatting

vs 2012 and framework3.5

-private void radTreeView1_NodeFormatting-

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Feb 2018, 12:38 PM
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.
0
José Miguel
Top achievements
Rank 1
answered on 23 Apr 2019, 10:15 PM

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;
            }
        }

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Apr 2019, 07:42 AM
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.
Tags
Treeview
Asked by
behnam
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
behnam
Top achievements
Rank 1
José Miguel
Top achievements
Rank 1
Share this question
or