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

Refreshing radTreeView with Bound List

20 Answers 1107 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Brad
Top achievements
Rank 2
Brad asked on 11 Jul 2008, 03:48 AM
Hi,

I have a radTreeView that is databound to a List.  After adding an item to my List how can I refresh the TreeView?

Currently only the items that were in the list when I first set the datasource are displayed.

Thanks,
Brad

20 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 14 Jul 2008, 08:00 AM
Hi Brad,

You can "refresh" RadTreeView by resetting the data binding. That is - set the DataSource property to null and then set it again to your source.

Generally speaking, RadTreeView should add new nodes for the new items in the data source automatically. And if it doesn't you may have found a bug in the data binding that must be corrected. It will be most helpful if you can send us a sample project that demonstrates the issue. It could also be in help if you explain in more detail what is the data and how you bind RadTreeView to it.

Thank you for your cooperation.

Regards,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Brad
Top achievements
Rank 2
answered on 15 Jul 2008, 10:14 PM
Hi Jordan,

Since having the problem with data binding I have reverted back to manually adding nodes.  What I can tell you is that I tried binding the data source in the constructor and then tried binding it in my add node button click event. (Neither worked correctly at the time)

Code used to bind:
radTreeViewExplorer.DisplayMember = "Name";
radTreeViewExplorer.DataSource = projectPipes;

The object type that I am binding to List: (Generics)
private List<Pipe> projectPipes = new List<Pipe>();

The Pipe class is fairly simple consisting mostly of properties.  One being "Name" which is what I linked to the display member.  I also tried linking the Value member to "Name" as well; that had no effect.

Regards,
Brad
0
Accepted
Nikolay
Telerik team
answered on 18 Jul 2008, 12:13 PM
Hi Brad,

Thank you getting back to us. Your code snippet helped me to better analyze your case.

If you want RadTreeView to be updated automatically when the DataSource collection is modified, you should use BindingList instead of List. For more information about BindingList, please refer to MSDN.

If you have additional questions, feel free to contact me.

Sincerely yours,
Nikolay
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Stargazer
Top achievements
Rank 2
answered on 20 Nov 2008, 12:12 PM
I there!

I've also a similar problem. I have a custom BindingList<T> implemented. It's a BindingList<MyObj>. I have my TreeView bound to it as such:
rtvComponentes.Nodes.Clear(); 
rtvComponentes.SelectedNode = null
rtvComponentes.DisplayMember = "Designacao"
rtvComponentes.ValueMember = "ID"
rtvComponentes.ParentIDMember = "ID_Parent"
rtvComponentes.DataSource = MyBOJ.ListObjs; // This is of type MyObjectList<Obj>, which in turn is a BindingList<T> 

I do that once, then I had new objects to the MyBOJ.ListObjs collection. The tree stays the same. Is it because of the binding being to self-related data?

Thanks!
0
Nikolay
Telerik team
answered on 25 Nov 2008, 08:47 AM
Hello Stargazer,

I was not able to reproduce any issue concerning the self-referencing data. I made a sample project which demonstrates that this scenario is working correctly on my side.

If your case is different, please open a new support ticket and send me a sample project. This will allow me to  to address any potential issue further and to give you more accurate response.

Sincerely yours,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jessie
Top achievements
Rank 1
answered on 17 Feb 2009, 01:44 AM
Hi Sir,

I would like to ask if how I could refresh the rad treeview when new node is added or deleted and all other controls when I click the refresh button. Here's is my code in splash screen upon loading(radtreeview) to main form...

Thank you and God bless...


 public void PopulateMessageTree()
        {
            radTreeMessages.BeginUpdate();

            foreach (var folder in collFolders.Where(x => x.ParentId == 0))
            {
                var node = new RadTreeNode(folder.Name) { ImageIndex = Constants.ICON_SMS_FOLDER, Tag = "ROOT", Key = folder.NodeId };
                radTreeMessages.Nodes.Add(node);

                FolderItem folder1 = folder;
                foreach (var smsFolder in collFolders.Where(x => x.ParentId == folder1.NodeId))
                {
                    var child = new RadTreeNode(smsFolder.Name) { ImageIndex = Constants.ICON_SMS, Tag = smsFolder.Name, Key = smsFolder.NodeId };
                    node.Nodes.Add(child);
                }
            }
            radTreeMessages.ExpandAll();
            radTreeMessages.EndUpdate();
        }// End of PopulateMessageTree
0
Victor
Telerik team
answered on 18 Feb 2009, 01:55 PM
Hi jessie,

Thank you for writing. I am sorry but I cannot infer anything about the code unless I see it in some kind of context. Also what do you mean by "refresh the rad treeview when new node is added or deleted and all other controls when I click the refresh button" ? The tree view refreshes automatically when nodes are added or removed.

Maybe if you send a sample project I will be able to assist you. I am looking forward to your reply.


All the best,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
alastairw
Top achievements
Rank 1
answered on 21 Dec 2009, 11:33 PM
Hello All,

I have just tried the sample and have added a textbox and this code

 

private void Form1_Load(object sender, EventArgs e)

 

{

textBox1.DataBindings.Add(

new Binding("Text", list, "name"));

 

}

The tree view doesnt update if i change the value in the textbox, but the underlying datasource does.


Aly suggestions?

Alastair

0
Victor
Telerik team
answered on 22 Dec 2009, 01:30 PM
Hello alastairw,

Please clarify what is the type of your data source. It must be a type which supports change notifications -- such as DataTable or BindingList<T>. Also if you are using custom objects, the type of your custom objects must support INotifyPropertyChanged interface. I am looking forward to your reply.

Greetings,
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
Amruta
Top achievements
Rank 1
answered on 22 Mar 2010, 07:55 AM
Hi,
I use a list of custom object to bind to the treeview. I use OnLoadDemand for a particular node. When i click on the node, i call a wcf service method (asynch call.). After completeing event i get a new list of items and i add this list to the child list of the treeview item. At this stage, i want to refresh the treeview item which will show me the newly created child nodes. Can i achieve this using INotifyPropertyChanged interface? (I dont want to refresh the whole treeview. If i make the itemSource null and then bind it again i am able to get the newly created child nodes, but it makes the tree collapse. I dont want to make the tree collapse. ).

Please can anyone suggest me a good solution for this?

Regards.

0
Victor
Telerik team
answered on 24 Mar 2010, 02:15 PM
Hi Amruta,

You need to bind RadTreeView to a list that supports change notifications, for example BindingList or DataTable. This will allow RadTreeView to refresh itself once the collection changes. If you need more granular tree view refreshes, your custom objects need to implement INotifyPropertyChanged.

Regards,
Victor
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
Regin Barranco
Top achievements
Rank 1
answered on 29 Mar 2010, 11:32 AM
Hi, I'm having a similar problem. I have a treeview that uses an xmldatasource. The treeview does not refresh even though the data has changed. My code that binds the control goes something like this:


<telerik:RadTreeView id="myTreeView" DataSourceID="myXmlDataSource" ..............................

---------

void onGroupListRetrieved(string myXml)
{
     myXmlDataSource.Data = myXml;
     myTreeView.DataBind();
}
0
Victor
Telerik team
answered on 29 Mar 2010, 01:33 PM
Hi Regin Barranco,

Your question refers to RadTreeView for ASP.NET Ajax. The current form is about RadTreeView for WinForms. Please post your question in the appropriate forum section in order to get proper reply for the Telerik team.

Thank you for your understanding.

Sincerely yours,
Victor
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
Umair
Top achievements
Rank 1
answered on 21 Jul 2010, 05:14 PM
Hi.

I am also having same kind of problem. I have a RadTreeView, which is bound to a customized list class which is inherited from

BindingList

 

<T>. The problem is when I call bindingList.Add(myItem), it throws this exception "Value was either too large or too small for an Int32." Although, it doesn't give any exception on adding if the list is not bound.

This is how I am binding the tree:

 

 


private
void BindTree()

 

{

 

    this.treeView.DataSource = null;

 

 

    this.treeView.DisplayMember = "SomeProperty";    
    this.treeView.ValueMember = "RecId";

 

 

    this.treeView.ParentIDMember = "ChildOf";

 

 

    this.treeView.DataSource = this.bindingList; //BindingList<Template>

 

 

    this.treeView.DataMember = "Template";

 

}

 

Kindly tell me if I am doing any mistake?

Thanks,
Umair

0
Victor
Telerik team
answered on 26 Jul 2010, 04:19 PM
Hello Umair,

Thank you for writing.

For some reason an overflow or underflow exception is occurring, but I was not able to reproduce it. Please prepare a small sample application that triggers this exception, so that I can debug it and provide a solution.

Please note that you have to open a new support ticket in order to attach your project.

I am looking forward to your reply.

Sincerely yours,
Victor
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 21 Mar 2011, 10:19 AM
Hi Stargazer,

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 on our latest release refer to this blog post.

All the best,
Stefan
the Telerik team
0
Reza
Top achievements
Rank 1
answered on 22 Nov 2013, 03:36 PM
Hi There,
It' s not good for me to refresh data source. Because my data source  is very big. So I want to change my tree (e.g. change one node parent manually without refreshing and then refresh my data source in ideal time). How can I Do that?
0
Stefan
Telerik team
answered on 25 Nov 2013, 09:12 AM
Hi Reza,

Thank you for writing.

If you bind the tree to a DataTable, than all changes you are doing will be "stacked" in the DataTable, and then you can push them back to the database by calling the Update method of the TableAdapter. More information is available here:

I hope this helps.

Regards,
Stefan
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 >>
0
Christopher
Top achievements
Rank 2
answered on 24 Sep 2015, 06:42 PM

Hi,

 I have a radTreeview bound to a BindlingList.  That BindingList contains custom objects that also contain BindingLists.  I use async await to populate the collections in the background.  This seems to be working in that my radTreeView is being updated.  

However, if I have a node expanded and an item selected...if the asynchronous populating of the treeView adds a new node...my treeview immediately collapses all the nodes.  I assume there is an easy way to prevent this?

 Thanks

0
Stefan
Telerik team
answered on 25 Sep 2015, 06:28 AM
Hi Christopher,

Thank you for writing.

Since all the nodes are getting collapsed, it seems the tree is updated/refreshed. If you know when this happens or what causes it, you can save the tree state (expanded nodes and scroll position) and restore it afterwards.

If you have issues achieving that, I would suggest that you open a support ticket, where you can attach your or a sample demonstrating the undesired . Once we have it, we will be able to investigate a look for a possible solution.

Regards,
Stefan
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Treeview
Asked by
Brad
Top achievements
Rank 2
Answers by
Jordan
Telerik team
Brad
Top achievements
Rank 2
Nikolay
Telerik team
Stargazer
Top achievements
Rank 2
jessie
Top achievements
Rank 1
Victor
Telerik team
alastairw
Top achievements
Rank 1
Amruta
Top achievements
Rank 1
Regin Barranco
Top achievements
Rank 1
Umair
Top achievements
Rank 1
Stefan
Telerik team
Reza
Top achievements
Rank 1
Christopher
Top achievements
Rank 2
Share this question
or