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

Treeview not updating list items

3 Answers 158 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan Black
Top achievements
Rank 1
Ryan Black asked on 14 Oct 2010, 05:03 PM
Hello Telerik!

I have created an example similar to your file explorer treeview example.  I am having trouble getting the list to automatically update if a text file is added.  I am not looking for a filewatcher solution, just something simple where a function is called once the file has been added.

Please check out my example here

To get it working add a c:\foo directory and at least 1 text file.   The desired result would be to have the treeview automatically update once the add file button is pressed.

Thanks.  You guys are the best!
Ryan

3 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 15 Oct 2010, 01:48 PM
Hi Ryan Black,

The RadTreeView will update itself accordingly when the data source changes, however in your setup this is not possible. The reason for this is that data source (FileModelDataSourceKind) does not update when a new file is created in the local file system. You would have to use something like a FileSystemWatcher to notify the source collection, which in turn will propagate changes to the RadTreeView.
 
Best regards,
Alex Fidanov
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
Ryan Black
Top achievements
Rank 1
answered on 15 Oct 2010, 01:53 PM
Alex,

Thanks for the reply.  

I am not looking to use a FileSystemWatcher as the solution.  I just want to have a method called that will alert the list that a file has been added.  This can be added below the line of me adding the text file to the c:\foo folder.

Thanks
Ryan
0
Alex Fidanov
Telerik team
answered on 15 Oct 2010, 02:27 PM
Hello Ryan Black,

In this case, you are looking for code something like this (given your current structure)

System.IO.File.WriteAllText(@"C:\foo\OurTestFile.txt", "This is a test.");
            RadTreeView treeView = this.fileExplorer.Template.FindName("folderTree", fileExplorer) as RadTreeView;
  
            if (treeView != null)
            {
                FileModelDataSource source = treeView.ItemsSource as FileModelDataSource;
                source.Add(new Directory(@"C:\foo\OurTestFile.txt","OurTestFile",false));
            }
However, I would recommend exposing the FileModelDataSource as a property of the FileExplorer control so that you can get the source right away and not use this error prone code.

Regards,
Alex Fidanov
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
Tags
TreeView
Asked by
Ryan Black
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Ryan Black
Top achievements
Rank 1
Share this question
or