RadTreeView winforms - DataBinding and Images

9 posts, 0 answers
  1. Seth
    Seth avatar
    90 posts
    Member since:
    Jun 2007

    Posted 09 Sep 2009 Link to this post

    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.
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 14 Sep 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Matthew Link
    Matthew Link avatar
    13 posts
    Member since:
    Oct 2009

    Posted 10 Sep 2010 Link to this post

    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
  5. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 17 Sep 2010 Link to this post

    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
  6. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 18 Mar 2011 Link to this post

    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
  7. Noah
    Noah avatar
    2 posts
    Member since:
    Apr 2008

    Posted 09 May 2011 Link to this post

    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?
  8. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 12 May 2011 Link to this post

    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.
  9. Aravind
    Aravind avatar
    3 posts
    Member since:
    Nov 2012

    Posted 30 Dec 2012 Link to this post

    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)
  10. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 03 Jan 2013 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready