2012-08-05 50 views
-1

可以说我有组合框填充项目(项目是这个特定示例的一些数字),并且我想告诉C#这样的事情:IF在组合框中选择了一些item,得到item和乘以2。有什么办法可以做到这一点?使用组合框的IF语句

+0

而且您使用WPF或WinForms的吗? – 2012-08-05 22:25:17

+0

'if(cbItems.SelectedItem == true)'我试过这个,但它不起作用,即时通讯新的C#。 – Anon1139 2012-08-05 22:30:03

+0

@Michel Keijzers WinForms – Anon1139 2012-08-05 22:30:27

回答

2

假设它是由一个int列表填充的。 e.g

for(int index = 0; index < 10; index++) 
{ 
    myCombobox.Add(index); 
} 

if (myCombobox.SelectedItem != null) 
{ 
    int value = ((int)myCombobox.SelectedItem) * 2; 
} 

的WinForms当然

如果是字符串那么这将是东西IKE

if (myCombobox.SelectedItem != null) 
{ 
    int value = int.Parse(myCombobox.SelectedItem.ToString()) * 2; 
} 
+0

感谢您的答案,这就是我一直在寻找的: ) – Anon1139 2012-08-05 22:53:25