vb listview 内容存入txt
SaveLWListView1,"c:\错误代码.txt"用这个命令是,存入txt文件的是控件内的所有字段,我现在只想存一列的内容,请问给为高手能给我个解答吗?...
SaveLW ListView1, " c:\错误代码.txt" 用这个命令是,存入txt文件的是控件内的所有字段,我现在只想存一列的内容,请问给为高手能给我个解答吗?
展开
2个回答
展开全部
/// <summary>
///
/// </summary>
/// <param name="listView1">listView</param>
/// <param name="FileName">存储的文件名</param>
/// <param name="columnIndex">listView需要存储第几列</param>
private void SaveLWColumn(ListView listView1, string FileName, int columnIndex)
{
int count = listView1.Items.Count;
if (!File.Exists(FileName))
{
try
{
File.Create(FileName);
}
catch (Exception ex)
{
MessageBox.Show("错误" + ex.Message);
return;
}
}
StreamWriter sw = new StreamWriter(FileName);
try
{
for (int i = 0; i < count; i++)
{
string value = listView1.Items[i].SubItems[columnIndex].Text.ToString();
sw.WriteLine("第" + (i + 1) + "列:" + value);
}
}
catch (Exception ex)
{
MessageBox.Show("错误" + ex.Message);
}
finally
{
sw.Close();
}
}
///
/// </summary>
/// <param name="listView1">listView</param>
/// <param name="FileName">存储的文件名</param>
/// <param name="columnIndex">listView需要存储第几列</param>
private void SaveLWColumn(ListView listView1, string FileName, int columnIndex)
{
int count = listView1.Items.Count;
if (!File.Exists(FileName))
{
try
{
File.Create(FileName);
}
catch (Exception ex)
{
MessageBox.Show("错误" + ex.Message);
return;
}
}
StreamWriter sw = new StreamWriter(FileName);
try
{
for (int i = 0; i < count; i++)
{
string value = listView1.Items[i].SubItems[columnIndex].Text.ToString();
sw.WriteLine("第" + (i + 1) + "列:" + value);
}
}
catch (Exception ex)
{
MessageBox.Show("错误" + ex.Message);
}
finally
{
sw.Close();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询