菜鸟一问?
我想在关闭对话筐的时候将LISTVIEW中的内容保存下来,DEBUG能通过但就是不能建立文件,0字节的文件都不能建立,为什么啊?
private void Form1_Closing(objectsender,System.ComponentModel.CancelEventArgs e)
{
StreamWriter sw=null;
try
{ sw = File.CreateText("save.txt");
ListView.ListViewItemCollection items=listView1.Items;
foreach ( ListViewItem item in items )
{
String string1,string2;
string1=item.SubItems[0].Text;
string2=item.SubItems[1].Text;
sw.WriteLine(string1);
sw.WriteLine(string2);
}
}
catch(Exception excep)
{
MessageBox.Show (excep.Message,"error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
finally
{
if(sw!=null)
{ sw.Flush();
sw.Close();
}
}
}
问题点数:0、回复次数:0Top




