Ejemplo n.º 1
0
 private void TriggerTree_Load(object sender, EventArgs e)
 {
     TreeView1.Nodes.Clear();
     TreeView1.Nodes.Add("Tree Root");
     TreeView1.BeginUpdate();
     AddNode(TreeView1.TopNode, 0);
     TreeView1.EndUpdate();
 }
Ejemplo n.º 2
0
 private void BuildTree()
 {
     TreeView1.BeginUpdate();
     Label6.Text = "Sounds: " + SoundCount.ToString() + " Interleave: " + Interleave.ToString();
     TreeView1.Nodes.Clear();
     for (int i = 0; i <= SoundCount - 1; i++)
     {
         string name = "ID: " + i.ToString() + " ";
         TreeView1.Nodes.Add(name + Sounds[i].Name);
     }
     TreeView1.EndUpdate();
 }
Ejemplo n.º 3
0
        private async Task PopulateTreeViewAsync()
        {
            TreeNode treeNode1 = TreeView1.TopNode;

            #region Before populating data.

            var timer = new Stopwatch();
            timer.Start();
            searchProgress.Visible = true;

            #endregion

            try
            {
                #region Fetch JSON from API.

                string fetchedComments = await client.GetStringAsync("https://jsonplaceholder.typicode.com/comments");

                string fetchedPosts = await client.GetStringAsync("https://jsonplaceholder.typicode.com/posts");

                string fetchedUsers = await client.GetStringAsync("https://jsonplaceholder.typicode.com/users");

                string fetchedToDos = await client.GetStringAsync("https://jsonplaceholder.typicode.com/todos");

                #endregion

                #region Deserialize JSON into JArray.

                JArray commentArray = JsonConvert.DeserializeObject <dynamic>(fetchedComments);
                JArray postArray    = JsonConvert.DeserializeObject <dynamic>(fetchedPosts);
                JArray userArray    = JsonConvert.DeserializeObject <dynamic>(fetchedUsers);
                JArray toDoArray    = JsonConvert.DeserializeObject <dynamic>(fetchedToDos);

                #endregion

                #region Convert JArrays into List<T>.

                foreach (var post in postArray)
                {
                    Post newPost = new Post();
                    JsonConvert.PopulateObject(post.ToString(), newPost);

                    posts.Add(newPost);
                }

                foreach (var comment in commentArray)
                {
                    Comment newComment = new Comment();
                    JsonConvert.PopulateObject(comment.ToString(), newComment);

                    comments.Add(newComment);
                }

                foreach (var todo in toDoArray)
                {
                    ToDo newToDo = new ToDo();
                    JsonConvert.PopulateObject(todo.ToString(), newToDo);

                    todos.Add(newToDo);
                }

                foreach (var user in userArray)
                {
                    User newUser = new User();
                    JsonConvert.PopulateObject(user.ToString(), newUser);

                    foreach (var todo in todos)
                    {
                        if (todo.UserId == newUser.ID)
                        {
                            newUser.ToDos.Add(todo);
                        }
                    }

                    foreach (var post in posts)
                    {
                        if (post.UserID == newUser.ID)
                        {
                            newUser.Posts.Add(post);
                        }
                    }

                    foreach (var comment in comments)
                    {
                        if (comment.PostID == newUser.ID)
                        {
                            newUser.Comments.Add(comment);
                        }
                    }

                    users.Add(newUser);
                }

                #endregion

                TreeView1.BeginUpdate();

                foreach (var user in users)
                {
                    treeNode1.Nodes.Add(user.Name);
                    treeNode1.Nodes[users.IndexOf(user)].Nodes.Add("Username");
                    treeNode1.Nodes[users.IndexOf(user)].Nodes[0].Nodes.Add(user.UserName);
                    treeNode1.Nodes[users.IndexOf(user)].Nodes.Add("Address");
                    treeNode1.Nodes[users.IndexOf(user)].Nodes[1].Nodes.Add($"Street: {user.Address.Street}");
                    treeNode1.Nodes[users.IndexOf(user)].Nodes[1].Nodes.Add($"City: {user.Address.City}");
                    treeNode1.Nodes[users.IndexOf(user)].Nodes[1].Nodes.Add($"ZipCode: {user.Address.ZipCode}");
                    treeNode1.Nodes[users.IndexOf(user)].Nodes.Add("Comments");
                    foreach (var comment in user.Comments)
                    {
                        treeNode1.Nodes[users.IndexOf(user)].Nodes[2].Nodes.Add($"Comment from {comment.Email} --- {comment.Body}");
                    }
                    treeNode1.Nodes[users.IndexOf(user)].Nodes.Add("Posts");
                    foreach (var post in user.Posts)
                    {
                        treeNode1.Nodes[users.IndexOf(user)].Nodes[3].Nodes.Add($"{post.Title} --- {post.Body}");
                    }
                }

                TreeView1.EndUpdate();
            }
            #region Exception Handling

            catch (HttpRequestException ex)
            {
                Console.WriteLine($"Exception Caught!\n{ex.Message}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception Caught!\n{ex.Message}");
            }

            #endregion

            #region After populating data.

            searchProgress.Visible = false;

            #endregion
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Passes through the EndUpdate method to the TreeView
 /// </summary>
 public void EndUpdate()
 {
     TreeView1.EndUpdate();
 }