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 /// summary> public class treeviewDataAccess {public TreeViewDataAccess () {} /// /// treeviewData //// summary > [Serializable ()] public struct treeviewdata {public treenodedata [] nodes;
/// /// recursive initialization TreeView data /// summary> /// param> 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 /// summary> /// param> 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 /// summary> /// ////// //> 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 /// summary> /// param> /// param> 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 /// summary> /// param> /// param> 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 ( );
}
}