Tri State Check Box Performance Issues

6 posts, 0 answers
  1. Gerry
    Gerry avatar
    26 posts
    Member since:
    Nov 2010

    Posted 06 Aug 2013 Link to this post

    Hi,

    I'm using your WinForm treeview. I am populating the nodes using the NodesNeeded event. LazyMode is set to false and AutoCheckChildNodes is set to true.

    Our data includes about 10 root notes. Some of the notes have over 30 000 nodes (many are parents with children). If we tick the root node, the tri state check box applies checks to all child nodes and ends up taking over a minute in some cases. If I disable AutoCheckChildNodes it doesn't appear to make any difference. If we just browse through the nodes and keep expanding different children, there is no issue, only when the status of a check box changes.

    Ideally we would like to see the tri check status to persist but it doesn't need to update children items until they are open.

    Thanks!
  2. George
    Admin
    George avatar
    500 posts

    Posted 09 Aug 2013 Link to this post

    Hi Gerry,

    Thank you for writing.

    Usually when AutoCheckChildNodes is set to true the NodesNeeded event is fired when a parent node is checked, but it works really fast even with 30 000 nodes. However when you are adding nodes on the NodesNeeded event you do a few extra operations each time the event is fired which when combined with hierarchy may become slow. Additionally if you are making queries to the database that would make it even slower. I would recommend you to enable LazyMode in the RadTreeView if possible. If this approach is not available for you I would be glad to help once you provide me some additional information.

    I hope this information is helpful. If you need any further assistance, please let me know.
     
    Regards,
    George
    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 >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Gerry
    Gerry avatar
    26 posts
    Member since:
    Nov 2010

    Posted 03 Sep 2013 Link to this post

    Thank you for your answer.

    I have tried using the TreeView in both lazy and non lazy mode. In my case I cannot use lazy mode because I need to know if there are nodes available to decide if an expand icon should show up. Here is the code involved. The objective is to show the file system structure. In my case my system has over 600 000 files and folders. When I check the C:\  check box it is instant but if I uncheck it takes 20-40 seconds. It appears it looks deeper in the file structure for some reason. The NodeFileInfo class is also shown in the code block.

        private void PopulateRoot(IList<Telerik.WinControls.UI.RadTreeNode> nodes)
        {
            foreach (DriveInfo DI in DriveInfo.GetDrives())
            {
                if (!(DI.RootDirectory.ToString().StartsWith("A:") || DI.RootDirectory.ToString().StartsWith("B:")))
                switch (DI.DriveType)
                {
                    case DriveType.Fixed:
                    case DriveType.Network:
                    case DriveType.Removable:
                        Telerik.WinControls.UI.RadTreeNode TN = new Telerik.WinControls.UI.RadTreeNode(DI.RootDirectory.ToString());
                        NodeFileInfo NFI = new NodeFileInfo();
                        NFI.Path = DI.RootDirectory.ToString();
                        NFI.PathType = "D";
                        TN.Tag = NFI;
                        nodes.Add(TN);
                        break;
                }
            }
        }
     
        private void trvBackupSource_NodesNeeded(object sender, Telerik.WinControls.UI.NodesNeededEventArgs e)
        {
            if (IgnoreNextNeedRequest)
            {
                IgnoreNextNeedRequest = false;
                return;
            }
            if (e.Parent == null)
            {
                this.PopulateRoot(e.Nodes);
            }
            else
            {
                NodeFileInfo NFIParent = (NodeFileInfo)e.Parent.Tag;
     
                if (NFIParent.PathType.ToUpper() == "D")
                {
                    // TODO: Won't load some folders due to user rights. Need to address this issue
     
                    try
                    {
                        foreach (string Dir in Directory.GetDirectories(NFIParent.Path))
                        {
                            Telerik.WinControls.UI.RadTreeNode TN = new Telerik.WinControls.UI.RadTreeNode(Dir, false);
                            NodeFileInfo NFI = new NodeFileInfo();
                            NFI.Path = Dir;
                            NFI.PathType = "D";
                            TN.Tag = NFI;
                            e.Nodes.Add(TN);
                        }
                    }
                    catch { }
     
                    try
                    {
                        foreach (string F in Directory.GetFiles(NFIParent.Path))
                        {
                            Telerik.WinControls.UI.RadTreeNode TN = new Telerik.WinControls.UI.RadTreeNode(F, false);
                            NodeFileInfo NFI = new NodeFileInfo();
                            NFI.Path = F;
                            NFI.PathType = "F";
                            TN.Tag = NFI;
                            e.Nodes.Add(TN);
                        }
                    }
                    catch { }
                }
            }
        }
     
        private bool IgnoreNextNeedRequest = false;
        private void trvBackupSource_NodeCheckedChanged(object sender, Telerik.WinControls.UI.TreeNodeCheckedEventArgs e)
        {
            this.btnBackupSourceSave.Enabled = true;
            this.btnBackupSourceUndo.Enabled = true;
            IgnoreNextNeedRequest = true;
        }
     
     
    class NodeFileInfo
    {
        private string _path = "";
        public string Path
        {
            get { return _path; }
            set { _path = value; }
        }
     
        private string _pathtype = "";
        public string PathType
        {
            get { return _pathtype; }
            set { _pathtype = value; }
        }
    }
  5. George
    Admin
    George avatar
    500 posts

    Posted 06 Sep 2013 Link to this post

    Hello Gerry,

    Thank you for writing back.

    In such custom cases the best approach would be create your own logic which will handle everything according to your needs. I have prepared a sample project which contains a RadTreeView which represents the files structure of your computer. I have handled NodeExpandedChanged,NodeCheckedChanging and NodeExpandedChanging events. Files/Directories are only loaded when a node is expanded and when a parent node is checked only the visible children are checked/unchecked. Please refer to the attached zip file for more details.

    Additionally in your case you can try using Begin/EndUpdate in your NodesNeeded event or stop directory traversal if when unchecking a node by raising some flag.

    I hope this helps.
     
    Regards,
    George
    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 >>
  6. Gerry
    Gerry avatar
    26 posts
    Member since:
    Nov 2010

    Posted 01 Oct 2013 Link to this post

    Thank you. I have been swamped so I will proceed to testing if this works for us (sounds like it will) and I'll provide feedback.
  7. George
    Admin
    George avatar
    500 posts

    Posted 04 Oct 2013 Link to this post

    Hello Gerry,

    Please, let us know if there is anything else.

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