TreeViewWord文件下载.docx
- 文档编号:15155786
- 上传时间:2022-10-28
- 格式:DOCX
- 页数:11
- 大小:15.90KB
TreeViewWord文件下载.docx
《TreeViewWord文件下载.docx》由会员分享,可在线阅读,更多相关《TreeViewWord文件下载.docx(11页珍藏版)》请在冰豆网上搜索。
,"
提示信息"
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
//创建一个节点对象,并初始化
try
ArrayListr=newArrayList();
Form3f=newForm3();
f.ShowDialog(this);
TreeNodetmp=newTreeNode(f.textBox1.Text);
r.Add(f.textBox1.Text.ToString());
r.Add(f.textBox2.Text.ToString());
r.Add(f.textBox3.Text.ToString());
r.Add(f.textBox4.Text.ToString());
r.Add(f.textBox5.Text.ToString());
r.Add(f.richTextBox1.Text.ToString());
tmp.Tag=r;
tmp.Text=f.textBox1.Text;
ArrayListt=(ArrayList)this.treeView1.SelectedNode.Tag;
if(System.Convert.ToDateTime(f.textBox2.Text.ToString())<
=System.Convert.ToDateTime(t[1].ToString()))
怎么可能!
"
treeView1.SelectedNode.Nodes.Add(tmp);
treeView1.SelectedNode=tmp;
treeView1.ExpandAll();
catch
正确输入日期!
privatevoidAddParent()
//首先判断是否选定组件中节点的位置
if(treeView1.SelectedNode.Parent==null)
f.ShowDialog();
TreeNodetmp=newTreeNode(f.textBox1.Text);
ArrayListt=(ArrayList)this.treeView1.SelectedNode.Parent.Tag;
if(System.Convert.ToDateTime(f.textBox2.Text)<
MessageBoxButtons.OK,MessageBoxIcon.Information);
treeView1.SelectedNode.Parent.Nodes.Add(tmp);
treeView1.ExpandAll();
//在TreeView组件中加入兄弟节点
遍历接点的算法:
publicTreeNodeFindNode(TreeNoderoot,stringstrValue)
if(root==null)
returnnull;
if(root.Text==strValue)
returnroot;
TreeNoder=null;
foreach(TreeNodenodeinroot.Nodes)
{
r=FindNode(node,strValue);
if(r!
=null)
break;
returnr;
序列化实现对TREEVIEW的存储:
///class2对TreeView进行序列化
///用于文件的存读;
///文件以二进制写入
publicclassTreeViewDataAccess
///TreeViewData
[Serializable()]
publicstructTreeViewData
publicTreeNodeData[]Nodes;
///递归初始化TreeView数据
publicTreeViewData(TreeViewtreeview)
Nodes=newTreeNodeData[treeview.Nodes.Count];
if(treeview.Nodes.Count==0)
return;
for(inti=0;
i<
=treeview.Nodes.Count-1;
i++)
Nodes=newTreeNodeData(treeview.Nodes);
///通过TreeViewData弹出TreeView
publicvoidPopulateTree(TreeViewtreeview)
if(this.Nodes==null||this.Nodes.Length==0)
treeview.BeginUpdate();
=this.Nodes.Length-1;
treeview.Nodes.Add(this.Nodes.ToTreeNode());
treeview.EndUpdate();
///TreeNodeData
publicstructTreeNodeData
publicstringText;
publicintImageIndex;
publicintSelectedImageIndex;
publicboolChecked;
publicboolExpanded;
publicobjectTag;
publicColorBackColor;
///TreeNode构造函数
publicTreeNodeData(TreeNodenode)
this.Text=node.Text;
this.ImageIndex=node.ImageIndex;
this.SelectedImageIndex=node.SelectedImageIndex;
this.Checked=node.Checked;
this.BackColor=node.BackColor;
this.Expanded=node.IsExpanded;
this.Nodes=newTreeNodeData[node.Nodes.Count];
this.Tag=node.Tag;
if(node.Nodes.Count==0)
=node.Nodes.Count-1;
Nodes=newTreeNodeData(node.Nodes);
///TreeNodeData返回TreeNode
publicTreeNodeToTreeNode()
TreeNodeToTreeNode=newTreeNode(this.Text,this.ImageIndex,this.SelectedImageIndex);
ToTreeNode.Checked=this.Checked;
ToTreeNode.BackColor=this.BackColor;
ToTreeNode.Tag=this.Tag;
if(this.Expanded)
ToTreeNode.Expand();
if(this.Nodes==null&
&
this.Nodes.Length==0)
if(ToTreeNode!
=null&
this.Nodes.Length==0)
returnToTreeNode;
ToTreeNode.Nodes.Add(this.Nodes.ToTreeNode());
///加载TreeView
publicstaticvoidLoadTreeViewData(TreeViewtreeView,stringpath)
BinaryFormatterser=newBinaryFormatter();
Streamfile=newFileStream(path,FileMode.Open,FileAccess.Read,FileShare.Read);
TreeViewDatatreeData=((TreeViewData)(ser.Deserialize(file)));
treeData.PopulateTree(treeView);
file.Close();
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- TreeView