• 大小: 38KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: C#
  • 标签:

资源简介

点击保存按钮,将treeview1中树状结构以二进制形式保存于d盘mytest.txt文件中 点击读取按钮,将d盘mytest.txt文件中记录的树状模型结构显示到treeview2中

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace treeviewDataAccess
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        /// 
        /// TreeView串行化类
        /// 

        public class TreeViewDataAccess
        {
            public TreeViewDataAccess() { }

            /// 
            /// TreeViewData
            /// 

            [Serializable()]
            public struct TreeViewData
            {
                public TreeNodeData[] Nodes;

                /// 
                /// 递归初始化TreeView数据
                /// 

                /// 
                public TreeViewData(TreeView treeview)
                {
                    Nodes = new TreeNodeData[treeview.Nodes.Count];
                    if (treeview.Nodes.Count == 0)
                    {
                        return;
                    }
                    for (int i = 0; i <= treeview.Nodes.Count - 1; i++)
                    {
                        Nodes[i] = new TreeNodeData(treeview.Nodes[i]);
                    }
                }

                /// 
                /// 通过TreeViewData弹出TreeView
                /// 

                /// 
                public void PopulateTree(TreeView treeview)
                {
                    if (this.Nodes == null || this.Nodes.Length == 0)
                    {
                        return;
                    }
                    treeview.BeginUpdate();
                    for (int i = 0; i <= this.Nodes.Length - 1; i++)
                    {
                        treeview.Nodes.Add(this.Nodes[i].ToTreeNode());
                    }
                    treeview.EndUpdate();
                }
            }

            /// 
            /// TreeNodeData
            /// 

            [Serializable()]
            public struct TreeNodeData
            {
                public string Text;
                public int ImageIndex;
                public int SelectedImageIndex;
                public bool Checked;
                public bool Expanded;
                public object Tag;
                public TreeNodeData[] Nodes;

                /// 
                /// TreeNode构造函数
                /// 

                /// 
                public TreeNodeData(TreeNode node)
                {
                    this.Text = node.Text;
                    this.ImageIndex = node.ImageIndex;
                    this.SelectedImageIndex = node.SelectedImageIndex;
           

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      24576  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\bin\Debug\treeviewDataAccess.exe

     文件      30208  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\bin\Debug\treeviewDataAccess.pdb

     文件       5632  2005-12-08 14:51  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\bin\Debug\treeviewDataAccess.vshost.exe

     文件       6574  2010-08-02 16:43  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Form1.cs

     文件       7182  2010-08-02 16:43  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Form1.Designer.cs

     文件       5814  2010-08-02 16:43  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Form1.resx

     文件        842  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\treeviewDataAccess.csproj.GenerateResource.Cache

     文件      24576  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\treeviewDataAccess.exe

     文件        180  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\treeviewDataAccess.Form1.resources

     文件      30208  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\treeviewDataAccess.pdb

     文件        180  2010-08-02 15:18  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\treeviewDataAccess.Properties.Resources.resources

     文件        825  2010-08-02 16:45  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\treeviewDataAccess.csproj.FileListAbsolute.txt

     文件        477  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Program.cs

     文件       1202  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties\AssemblyInfo.cs

     文件       2892  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties\Resources.Designer.cs

     文件       5612  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties\Resources.resx

     文件       1103  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties\Settings.Designer.cs

     文件        249  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties\Settings.settings

     文件       3243  2010-08-02 15:18  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\treeviewDataAccess.csproj

     文件        943  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess.sln

    ..A..H.     12800  2010-08-02 16:46  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess.suo

     文件        144  2010-08-02 16:46  treeviewDataAccess\说明.txt

     目录          0  2010-08-02 15:19  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\Refactor

     目录          0  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug\TempPE

     目录          0  2010-08-02 15:18  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\bin\Debug

     目录          0  2010-08-02 15:33  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj\Debug

     目录          0  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\bin

     目录          0  2010-08-02 15:18  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\obj

     目录          0  2010-08-02 15:09  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess\Properties

     目录          0  2010-08-02 16:43  treeviewDataAccess\treeviewDataAccess\treeviewDataAccess

............此处省略5个文件信息

评论

共有 条评论

相关资源