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

RadTreeView winforms - DataBinding and Images

8 Answers 627 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Seth
Top achievements
Rank 1
Seth asked on 09 Sep 2009, 11:10 AM
I am using a BindingList object as my datasource and I would like to use an image list to display images in my treeview.  I looked for an ItemDataBound event or something similiar, but I did not see it.  I tried to use the DrawNode Event but I would get an error saying that the ImageIndex Property could not be updated because the treeview was in lock mode or something along those lines.  How do you suggest adding images when databinding?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 14 Sep 2009, 07:07 AM
Hello Seth,

When you assign a data source to RadTreeView, its nodes collection fires CollectionChanged event. You can subscribe to this event and assign images to the nodes as needed. In order to determine whether the treeview fires CollectionChanged upon data binding you can create a boolean flag. The example below demonstrates this:

radTreeView1.Nodes.CollectionChanged += new Telerik.WinControls.Data.NotifyCollectionChangedEventHandler(Nodes_CollectionChanged); 
myFlag = true
radTreeView1.DataSource = lst; 
myFlag = false
 
void Nodes_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e) 
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Add) 
    { 
        if (myFlag) 
        { 
            // Assign images here. 
            ((RadTreeNode)e.NewItems[0]).Image = null
        } 
    } 

Thank you for pointing out this omission in RadTreeView. We will add an ItemDataBound event in Q3 2009.

Please note that only customers receive free support. Please renew your subscription. 

Best wishes,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matthew Link
Top achievements
Rank 1
answered on 10 Sep 2010, 03:10 PM
Is this still the appropriate method to use when trying to set images while databinding?  I'm using 2010 Q2 SP1 and I notice that there is still not an ItemDataBound event.

Thanks!
Matthew
0
Stefan
Telerik team
answered on 17 Sep 2010, 03:54 PM
Hi Matthew Link,

Thank you for contacting us.
 
The approach for setting images on RadTreeView nodes has been slightly changed. Please refer to the following code snippet:
void Form1_Shown(object sender, EventArgs e)
{
    SetImages(radTreeView1.Nodes);
}
 
void SetImages(RadTreeNodeCollection  NodesCollection)
{
    foreach (RadTreeNode node in NodesCollection)
    {
        if (node.Nodes.Count == 0)
        {
            node.ImageIndex = 0;
            node.SelectedImageIndex = 1;
            node.StateImageIndex = 2;
        }
        else if (node.Nodes.Count > 0)
        {
            node.ImageIndex = 0;
            foreach (RadTreeNode childNode in node.Nodes)
            {
                SetImages(node.Nodes);
            }
        }
    }
}

All the best,
Stefan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Stefan
Telerik team
answered on 18 Mar 2011, 08:27 AM
Hi Matthew Link,

Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out.
For more information about this release, please refer to this blog post.
 
Kind regards,
Stefan
the Telerik team
0
Noah
Top achievements
Rank 1
answered on 09 May 2011, 10:48 PM
Is this still the best way to do this?

I have a RadTreeView that is dataBound to a self referencing table.
I would like to have a column in the table that corresponds to the ID field of an ImageList that i am using.

or do I still have to use recursion to loop threw all the nodes and assign there images?
0
Stefan
Telerik team
answered on 12 May 2011, 07:40 AM
Hi Matthew,

Thank you for writing.

If you have a populated ImageList and you have a column in the data source which holds an index valid for the ImageList, you can access this column value through the DataBoundItem property of RadTreeNode. Here is an example, where I am setting the ImageIndex of a node to the value that the first column of the data row returns (it is ID and holds the index):
void radTreeView1_NodeFormatting(object sender, Telerik.WinControls.UI.TreeNodeFormattingEventArgs e)
{
    DataRowView dataRowView = e.Node.DataBoundItem as DataRowView;
    e.Node.ImageIndex = Convert.ToInt32(dataRowView[0]);
}

I hope this helps.

Regards,
Stefan
the Telerik team
Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
0
Aravind
Top achievements
Rank 1
answered on 31 Dec 2012, 03:41 AM
hi
i am use radtreeview in my project,after i add a file in the radtreeview it does not show in the radtreeview,if i add parent node or child node it show ,but it add file it does not show in the treeview,if i close and open project then only it show the file ,
  pls reply me how to refresh the treeview,i use update(),Endupdate(),invalid(),refersh(),treeview1_SelectedNode(Nothing,Nothing)
0
Stefan
Telerik team
answered on 03 Jan 2013, 09:43 AM
Hello Aravind,

Thank you for writing.

I would suggest that you open a new support thread with your inquiry, in order to avoid mixing different scenarios in the same thread. This way, it will be easier for the community to find the information needed. See p4 from this thread: http://www.telerik.com/community/forums/winforms/treeview/important-information-on-using-the-telerik-forums.aspx.

Furthermore, in the support thread you can attach a sample project where the undesired behavior can be reproduced and our support team will look into it for you.

Regards,
Stefan
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
Treeview
Asked by
Seth
Top achievements
Rank 1
Answers by
Victor
Telerik team
Matthew Link
Top achievements
Rank 1
Stefan
Telerik team
Noah
Top achievements
Rank 1
Aravind
Top achievements
Rank 1
Share this question
or