ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • TreeView 전체경로(Full Path)로 찾아서 트리뷰에 표시하기
    c# Winform 개발/UI 2021. 6. 15. 16:11

    private TreeNode FindNode(TreeNode node, List<string> path)
            {
                path.RemoveAt(0);

                if (path.Count == 0)
                    return node;

                node.Expand();

                foreach (TreeNode mynode in node.Nodes)
                    if (mynode.Text == path[0])
                    {
                        return FindNode(mynode, path); //recursive call
                    }

                return node;
            }

     

    // gFilePath에 전체경로를 넣어주면 동작함

    private void btn_Load_Click(object sender, EventArgs e)
            {
                var path_list = gFilePath.Split('\\').ToList();
                foreach (TreeNode node in treeView1.Nodes)
                    if (node.Text.Replace("\\","") == path_list[0])
                    {
                        treeView1.SelectedNode = FindNode(node, path_list);
                        treeView1.Focus(); // 선택한 Node 보이게
                        break;
                    }
                
                LoadFileView();
            }

     

     

     

    300x250

    댓글

Designed by Tistory.