C#中,我用listview控件,在用textbox获取它的值怎么都是listviewsubitem:{张三}? 10
3个回答
展开全部
我也碰到一样的情况,我是导出到CSV里面,结果每个单元格都会有个 listviewsubitem:{内容},求大神
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
string path = string.Empty;
if (foldPath.EndsWith("\\"))
{
path = @foldPath + "VPD " + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss") + ".CSV";
}
else
{
path = @foldPath + "\\VPD " + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss") + ".CSV";
}
try
{
StreamWriter sw = new StreamWriter(path, false, Encoding.Default);
foreach (ListViewItem item in listView1.Items)
{
sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", item.SubItems[0], item.SubItems[1], item.SubItems[2], item.SubItems[3], item.SubItems[4], item.SubItems[5], item.SubItems[6]);
}
sw.Close();
MessageBox.Show("导出完成");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void button3_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.Description = "请选择文件路径";
if (dialog.ShowDialog() == DialogResult.OK)
{
string foldPath = dialog.SelectedPath;
string path = string.Empty;
if (foldPath.EndsWith("\\"))
{
path = @foldPath + "VPD " + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss") + ".CSV";
}
else
{
path = @foldPath + "\\VPD " + DateTime.Now.ToString("yyyy年MM月dd日HH时mm分ss") + ".CSV";
}
try
{
StreamWriter sw = new StreamWriter(path, false, Encoding.Default);
foreach (ListViewItem item in listView1.Items)
{
sw.WriteLine("{0},{1},{2},{3},{4},{5},{6}", item.SubItems[0], item.SubItems[1], item.SubItems[2], item.SubItems[3], item.SubItems[4], item.SubItems[5], item.SubItems[6]);
}
sw.Close();
MessageBox.Show("导出完成");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询