在c#中的richTextBox中添加listview项的问题 [英] problem with add listview items in richTextBox in c#

查看:69
本文介绍了在c#中的richTextBox中添加listview项的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


i希望将listview中的子项添加到RichTextBox中,我这样做但它会在其中创建空格行

这是我的问题的图片 [ ^ ]

如何从富文本框中删除这些空格行?

这是我的代码

Hi i want to add subitems from listview to RichTextBox and i do it but it make space lines in that
This is the picture of my problem[^]
how can i remove these space lines from rich textbox?
and this is my code

string fileName = "a.bat";
using (var writer = new StreamWriter(fileName))
{
    foreach (ListViewItem item in slv.Items)
    {
        for (int i = 0; i < slv.Items.Count; i++)
        {
            string a = item.SubItems[i].Text.Replace(item.Text, "");
            a=a.Replace(Convert.ToChar(10),' ');
            a=a.Replace(" ","");
            richTextBox1.Text += a + "\n";
        }
    }
}



最好的问候


Best Regards

推荐答案

如果您要做的只是从ListView中的第二列获取值,并将其写入RichTextBox:
If all you want to do is get the value from the second column in the ListView, and write it to the RichTextBox:
private string space = " ";
private string newLineString = Environment.NewLine;

private void WriteLvToRtfBox_Click(object sender, EventArgs e)
{
    foreach (ListViewItem lvItem in listView1.Items)
    {
        richTextBox1.Text +=                       
            lvItem.SubItems[1]
            .Text
            .Replace(newLineString, String.Empty)
            .Replace(space, String.Empty)
            + newLineString; 
    }
}


这篇关于在c#中的richTextBox中添加listview项的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆