我有这个comboBox项目:
A6 - Tiger
A79 - Eagle
B6789- Elephant
B69679 - Monkey
C67 - Whale
D - Dragon我如何在textBox中显示只有Tiger,Eagle Elephant字符串的selectedItem……没有A6、A79、B6789 ??
我在处理固定数量的char时使用了以下代码:
string temp = comboBox1.Text;
char[] array1 = temp.ToCharArray();
textBox1.Text = "" + array1[0] + array1[1];发布于 2013-07-24 11:14:31
我假设"A6 - Tiger“是你的文本格式。
你可以试试这个:
if (comboBox1.SelectedIndex > 0)
{
textBox1.Text = comboBox1.Text.Substring(comboBox1.Text.IndexOf('-') + 1).Trim();
}发布于 2013-07-23 15:57:01
假设您有SelectedItem
textBox1.Text = theSelectedItem.Split('-')[1].Trim()发布于 2013-07-23 16:03:02
在我看来,您的代码似乎只想显示A6、A79、B6789……所以我发布了这两个问题的解决方案
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{//Last
string s = (string)listBox1.SelectedItem;
string last = s.Substring(s.LastIndexOf(' ') + 1);
textBox1.Text = last;
listBox1_SelectedIndexChanged_first(sender, e);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{//First
string s = (string)listBox1.SelectedItem;
string first = s.Substring(0, s.IndexOf(' '));
textBox1.Text = first;
}https://stackoverflow.com/questions/17804453
复制相似问题