コード例 #1
0
        private void Load(TreeViewItem item)
        {
            item.Items.Clear();

            if (item.Tag is DirectoryInfo directory)
            {
                item.Cursor = Cursors.Wait;
                item.BeginInit();

                try
                {
                    foreach (var subDirectory in directory.GetDirectories())
                    {
                        if (!subDirectory.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            item.Items.Add(CreateItem(subDirectory));
                        }
                    }

                    foreach (var file in directory.GetFiles())
                    {
                        if (!file.Attributes.HasFlag(FileAttributes.Hidden))
                        {
                            item.Items.Add(CreateItem(file));
                        }
                    }
                }
                catch (Exception e)
                {
                    item.Items.Add(CreateErrorItem(e));
                }

                item.EndInit();
                item.Cursor = Cursors.Hand;
            }
        }