Treeview not updating list items

4 posts, 0 answers
  1. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 14 Oct 2010 Link to this post

    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
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 15 Oct 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Ryan Black
    Ryan Black avatar
    54 posts
    Member since:
    Mar 2010

    Posted 15 Oct 2010 Link to this post

    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
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 15 Oct 2010 Link to this post

    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
Back to Top