Sequence of tree control TreeView

xiaoxiao2021-03-05  23

Recently, I have made a small software, a file browser, compared with the Windows resource manager, you can view the contents of the file, without opening, supporting a variety of file formats, ready to join the content-based search (intend to open source Dotlucene components). There is a need to sequence the tree control, check a lot of information, find a VB.NET in CodeProject, and find a code converter to turn into C #, modified, changed to binary serialization. A reference for the next supply below.

Original address:

http://www.codeproject.com/vb/net/treeviewDataAccess.asp

I modified the C # source code:

Using system.io; using system.windows.forms; using system.runtime.serialization.formatters.binary;

Namespace Testall {///

/// TreeView Serialized Class /// public class treeviewDataAccess {public TreeViewDataAccess () {} /// /// treeviewData //// [Serializable ()] public struct treeviewdata {public treenodedata [] nodes;

///

/// recursive initialization TreeView data /// /// 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 pop-up TreeView /// /// public treenodedata (TREENODE Node) {THIS.TEXT = node.Text; this.ImageIndex = node.ImageIndex; this.SelectedImageIndex = node.SelectedImageIndex; this.Checked = node.Checked; this.Expanded = node.IsExpanded; this.Nodes = new TreeNodeData [node.Nodes.Count] ;

IF ((node.tag == null) && node.tag.gettype (). isserializable) {this.tag = node.tag;} else {this.tag = null;}} (node.nodes.count == 0) {return;} for (int i = 0; i <= node.nodes.count - 1; i ) {nodes [i] = new treenodedata (node.nodes [i]);}}

///

/// Treenodedata Returns Treenode /// /// Public TREENODE TOTREENODE () {TREENODE TOTREENODE = New Treenode (this.text, this.imageIndex, this .SelectedImageIndex; Totreenode.checked = this.checked; Totreenode.Tag = this.tag; if (this.expanded) {Totreenode.expand ();} if (this.nodes == null&im ".nodes.Length == 0) {RETURN NULL;} if (Totreenode! = Null && this.nodes.Length == 0) {Return Totreenode;} for (int i = 0; i <= this.nodes.length - 1; i ) {Totreenode .Nodes.add (this.nodes [i] .totreenode ());} Return Totreenode;}} /// /// Load TreeView /// /// /// public static void LoadTreeViewData (TreeView treeView, string path) {BinaryFormatter ser = new BinaryFormatter (); Stream file = new FileStream (path, FileMode .Open, fileaccess.read; treeshare.read; TreeViewData Treedata = ((Treev IEWDATA) (SER.DSERIALIZE (File)); TreeData.PopulaterTree (TreeView); file.close ();

}

///

/// Save TreeView to File /// /// /// public static void SaveTreeViewData (TreeView treeView, string path) {BinaryFormatter ser = new BinaryFormatter (); Stream file = new FileStream (path, FileMode.Create); ser.Serialize (file, new TreeViewData (treeView)); file.Close ( );

}

}

转载请注明原文地址:https://www.9cbs.com/read-37759.html

New Post(0)