試試這個:
var foo = str.Split(' '); //from 111 Simon will get '111'
var id = foo.Length > 1 ? foo[0] : null;
if(id != null) {
//do something with '111';
} else {
//error
}
編輯
我建議你做通過使用自定義Combobox
類:
public class Foo
{
public string Text { get; set; }
public int Value { get; set; }
public Foo(int id, string name)
{
Value = id;
Text = name;
}
public override string ToString()
{
return Text;
}
}
然後添加object
(富)爲combobox
:
comboBox1.Items.Add(new Foo(111, "simon"));
然後你就可以通過鑄造SelectedItem
屬性類訪問值:所選擇的響應
//assuming that comboBox1.SelectedText is "simon", the following is true:
var val = (Foo)comboBox1.SelectedItem;
val.Value // 111
val.Text // simon
'comboBox1.SelectedText.Split('')' – 2012-07-16 15:01:34
這會返回什麼? mySplit [0] = 111和mySplit [1] = Simon? – phadaphunk 2012-07-16 15:02:49
是的,它會........... – 2012-07-16 15:04:09