2016-01-06 79 views
0

我想將Combobox.SelectedValue作爲新元素髮送到數組中。C#將選定值的組合框添加到數組中

public MainWindow() 
{ 
     Combobox.DisplayMemberPath = "Text"; 
     Combobox.SelectedValuePath = "Value"; 
     Combobox.Items.Add(new { Text = "String", Value = 7 }); 
     Combobox.Items.Add(new { Text = "String", Value = 2 }); 

     ClassName[] array = ClassName[30]; 
     array[0] = Combobox.SelectedValue(); 
} 
+3

您的問題是什麼? –

+0

你想發送基於點擊按鈕或應該發生什麼時候選定的值? –

+0

是的基於按鈕點擊。 –

回答

0

您不能隱式地將SelectedValue返回類型(字符串)強制轉換爲ClassName。如果將數組更改爲字符串數組string []數組,則代碼應該可以工作

+0

如果您具有所需的變量,您還可以將新的ClassName元素添加到數組中。 –

+0

如何做到這一點? –

+0

public class ClassName public string SomeString {get; set;} } array [0] .SomeString = Combobox.SelectedValue(); – Gene