Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
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
Posted
Comments
Marcin Kozub 26-Nov-14 13:16pm    
Can you post what output you need? What data should be added and in what order?
Avenger1 26-Nov-14 14:11pm    
i said in that picture everything
delete empty lines, this is what i want
With Respect

1 solution

If all you want to do is get the value from the second column in the ListView, and write it to the RichTextBox:
C#
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; 
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900