2014-07-15 81 views
0

當我的應用程序啓動我得到從下拉框第一次發射空,但是當我改變它,我得到推出正確的結果組合框的值空

public partial class MainScreen : Page 
    { 
     SQLReader sql; 

     public MainScreen() 
     { 
      InitializeComponent(); 

      sql = new SQLReader(); 
      List<string> st = sql.getQuery("SELECT Name FROM Positions"); 

      PrCombo.ItemsSource = st; 
      PrCombo.SelectedIndex = 0; 

     } 

     private void PrCombo_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 
      string st = PrCombo.Text; //is null when the app starts 

     } 


    } 
+0

'string st = PrCombo.Text; //在應用程序啓動時爲空值 - 當然,它在'SelectionChanged'事件中。解釋你的最終目標是什麼? – DGibbs

+0

要閱讀PrCombo(combobox)數據 – Dim

+0

http://msdn.microsoft.com/en-us/library/system.windows.controls.selectionchangedeventargs%28v=vs.110%29.aspx – stijn

回答

0

嘗試訪問選定的項目,除了組合框的文本。

string st = PrCombo.SelectedItem.ToString();