问题描述
我是想一直点击button1的时候保存当前所有column。当点击button2的时候就使用之前压入堆栈里的columns恢复表头。谢谢啦,贴上testcode:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacestack{publicpartialclassForm1:Form{publicSystem.Collections.Stackhistory=newSystem.Collections.Stack();publicintnum=0;publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){++num;this.listView1.Columns.Clear();this.listView1.Columns.Add("标题"+num.ToString(),100);this.listView1.Columns.Add("内容"+num.ToString(),100);history.Push(listView1.Columns);}privatevoidbutton2_Click(objectsender,EventArgse){if(history.Count<1)return;--num;ListView.ColumnHeaderCollectioncolumns=(ListView.ColumnHeaderCollection)history.Pop();MessageBox.Show(columns.Count.ToString(),history.Count.ToString());listView1.Columns.Clear();foreach(ColumnHeaderchincolumns)listView1.Columns.Add(ch);}}}
解决方案
解决方案二:
只要执行了clear就会连之前压入堆栈的数据一起清零,不知道什么原因,新手,求赐教。
解决方案三:
求指点,十分感谢……