C#列表框索引更改 [英] C# List Box Index Change

查看:71
本文介绍了C#列表框索引更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在下面查看我的代码,在我的代码中,一旦更改索引值,就会在richtextBox中发生文本更改,但我的问题是一旦更改索引值,最终值只显示在richtextbox中,我需要保留所有更改在每个索引中。请尽快帮忙。谢谢!



Kindly review my code below, in my code, once change index value there are text changes happen in the richtextBox, but my problem is once change index values, final value only display in the richtextbox, I need to kept all the changes in every index. Please help asap. Thanks!

for (int i = 0; i < listBox1.Items.Count; i++)
            {

                listBox1.SelectedIndex = i;
                textBox2.Text = Regex.Replace((listBox1.Text), @"<a([^>]*)>&sect;([\d]+)", "Section $2").ToString();
                textBox3.Text = Regex.Match((listBox1.Text), @"id=""([^\s]*)""").ToString();
                richTextBox2.Text = Regex.Replace((richTextBox1.Text), @" " + textBox2.Text + " ", " <a " + textBox3.Text + ">" + textBox2.Text + "</a> ").ToString();
           
 }

推荐答案

2)。ToString();
textBox3 .Text = Regex.Match((listBox1.Text), @ id =([^ \s] *))。ToString();
richTextBox2.Text = Regex.Replace((richTextBox1.Text), @ < span class =code-string> + textBox2.Text + < a + textBox3.Text + > + textBox2.Text + < / a>)。ToString();

}
2").ToString(); textBox3.Text = Regex.Match((listBox1.Text), @"id=""([^\s]*)""").ToString(); richTextBox2.Text = Regex.Replace((richTextBox1.Text), @" " + textBox2.Text + " ", " <a " + textBox3.Text + ">" + textBox2.Text + "</a> ").ToString(); }






根据您的问题描述,您希望所有更改都列在richTextBox2中,对吧?如果是这样,您的代码修改es每次迭代中的richTextBox2文本,只留下最终值。我认为你应该做的是,将更改连接到richTextBox2。

Hi,

According to your problem description you want all changes to be listed in the richTextBox2, right? If so, your code modifies the Text of richTextBox2 in each iteration and only the final value will be left there. I think what you should do is, concatenate the changes in to the richTextBox2.
richTextBox2.Text += (Regex.Replace((richTextBox1.Text), @" " + textBox2.Text + " ", " <a " + textBox3.Text + ">" + textBox2.Text + "</a> ") + "\n");



问候。


Regards.


这篇关于C#列表框索引更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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