获取listBox中的textBox项 [英] Getting textBox Items in listBox
本文介绍了获取listBox中的textBox项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文本框,其中输入了项目。每个项目用#分隔。
我想获得listBox中的每个项目。
点击按钮怎么做
I have a textBox in which items are entered.Each item is separated by #.
I want to get every item in listBox .
how to do that with a button click
private void button1_Click(object sender, EventArgs e)
{
}
推荐答案
首先,拆分文本框的字符串。然后使用AddRange
方法将所有项目添加到列表框中。
First, split the string of the textbox. Then use theAddRange
method to add all items to the listbox.
private void button1_Click(object sender, EventArgs e)
{
string[] items = yourTextBoxNameHere.Text.Split('#');
yourListBoxNameHere.Items.AddRange(items);
}
或
确定文本或值的第一个数组值。请参阅以下代码
Or
Determine your first array value for text or value. See the following code
protected void Button1_Click(object sender, EventArgs e)
{
string[] splitvalues = txtListvalues.Text.Split('#');
ListBox1.Items.Add(new ListItem() { Value = splitvalues[0], Text = splitvalues[1] });
}
这篇关于获取listBox中的textBox项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文