K
K
Ksenya232015-03-18 16:49:07
Counts
Ksenya23, 2015-03-18 16:49:07

How to get the descendants of a node in the tree on the first request of the user?

Hello. I am faced with the task of adding child elements of the node selected when clicking to the tree.
The handler is called before the form is loaded.
There is a similar topic on the forum that does not have a solution, unfortunately. I ask for help in this matter.
Trying to view resulted in an error:

private void CreateControls()
            {
                TreeView = new TreeView();
               
                foreach (TreeNode trn in TreeView.Nodes)
                {
                    trn.SelectAction = TreeNodeSelectAction.Expand; //задаем свойства 
                }
                TreeView.TreeNodeExpanded += OnTreeNodeExtended; //для выбранных элементов назначаем обработчик
             } 
 
      private void OnTreeNodeExtended(object sender, TreeNodeEventArgs e)
            {
                string organizationName = (string)e.Node.DataItem; //в последующем коде возникнет ошибка по причине отсутствия выбранного элемента
                organizationName = (organizationName != null)? organizationName: "";
                var q = new Query<USER_CL_Entity>(LoadMode.Table);
                q.SA.Criteria["NOTE"] = organizationName;
                IEnumerable<USER_CL_Entity> users = q.Search();
 
                foreach (USER_CL_Entity user in users)
                {
                    e.Node.ChildNodes.Add(new TreeNode(user.SURNAME_PATRON));
                }
            }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question