How do i use a richTextBox instead of ListBox?
<p>I have this code im using listBox:</p>

<pre><code>private void button6_Click(object sender, EventArgs e)
        {

            using (var w = new StreamWriter(keywords))
            {
                crawlLocaly1 = new CrawlLocaly();
                crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
                DialogResult dr = crawlLocaly1.ShowDialog(this);
                if (dr == DialogResult.OK)
                {
                    int line = listBox1.Items.Count;
                    if (LocalyKeyWords.ContainsKey(mainUrl))
                    {
                        line = listBox1.Items.IndexOf("Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
                        listBox1.Items.Remove("Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
                        LocalyKeyWords[mainUrl].Clear();
                        LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
                    }
                    else
                    {
                        LocalyKeyWords[mainUrl] = new List&lt;string&gt;();
                        LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
                    }
                    Write(w);
                    listBox1.Items.Insert(line, "Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
                }
                if (dr == DialogResult.Cancel)
                {
                    Write(w);
                }
            } 
        }


        private void LoadKeys(Dictionary&lt;string,List&lt;string&gt;&gt; dictionary, string FileName)
        {
           string line = System.String.Empty;
           using (StreamReader sr = new StreamReader(keywords))
           {
            while ((line = sr.ReadLine()) != null)
            {
                string[] tokens = line.Split(',');
                dictionary.Add(tokens[0], tokens.Skip(1).ToList());
                listBox1.Items.Add("Url: " + tokens[0] + " --- " + "Localy KeyWord: " + tokens[1]);
            }
           } 
        }

        private void Write(StreamWriter writer)
        {
            foreach (KeyValuePair&lt;string, List&lt;string&gt;&gt; kvp in LocalyKeyWords)
            {
                writer.WriteLine(kvp.Key + "," + string.Join(",", kvp.Value));
            }
        }
</code></pre>

<p>Then i wanted to use richTextBox instead of listBox so i tried this code but its not working like the listBox did . Its showing me only one link and not acting like the listBox did. How can i fix it with the richTextBox ?</p>

<p>private void button6_Click(object sender, EventArgs e)
        {</p>

<pre><code>        using (var w = new StreamWriter(keywords))
        {
            crawlLocaly1 = new CrawlLocaly();
            crawlLocaly1.StartPosition = FormStartPosition.CenterParent;
            DialogResult dr = crawlLocaly1.ShowDialog(this);
            if (dr == DialogResult.OK)
            {
                int line = richTextBox2.GetLineFromCharIndex(richTextBox2.TextLength) + 1;
                if (LocalyKeyWords.ContainsKey(mainUrl))
                {
                    line = richTextBox2.Text.IndexOf("Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
                    richTextBox2.Text.Remove(line); //"Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
                    LocalyKeyWords[mainUrl].Clear();
                    LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
                }
                else
                {
                    LocalyKeyWords[mainUrl] = new List&lt;string&gt;();
                    LocalyKeyWords[mainUrl].Add(crawlLocaly1.getText());
                }
                Write(w);
                richTextBox2.Text.Insert(line, "Url: " + mainUrl + " --- " + "Localy KeyWord: " + LocalyKeyWords[mainUrl][0]);
            }
            if (dr == DialogResult.Cancel)
            {
                Write(w);
            }
        } 
    }


    private void LoadKeys(Dictionary&lt;string,List&lt;string&gt;&gt; dictionary, string FileName)
    {
       string line = System.String.Empty;
       using (StreamReader sr = new StreamReader(keywords))
       {
        while ((line = sr.ReadLine()) != null)
        {
            string[] tokens = line.Split(',');
            dictionary.Add(tokens[0], tokens.Skip(1).ToList());
            richTextBox2.Text = "Url: " + tokens[0] + " --- " + "Localy KeyWord: " + tokens[1];
        }
       } 
    }

    private void Write(StreamWriter writer)
    {
        foreach (KeyValuePair&lt;string, List&lt;string&gt;&gt; kvp in LocalyKeyWords)
        {
            writer.WriteLine(kvp.Key + "," + string.Join(",", kvp.Value));
        }
    }
</code></pre>
