2013-10-22 72 views
0

問題:不設置到對象的實例如何referesh內容在列表框,以避免未將對象引用設置到對象的實例

對象引用(在單擊某個項目在GridView中第二次) 。

此對象以某種方式引用UoMCollection.Clear()和此處遇到的問題:txtBlkUoM.Text = Uom.UoM.ToString();

 

-1-- Declare this in the page 

    ObservableCollection UoMCollection = new ObservableCollection(); 


-2-- Gridview : Click an item in GridView, it will do the following: 

PopUpItem.IsOpen = true; (this is the popUp Box) 

GetAllUoMForThisItem(No); 


-2-- This will fill up another ListBox calls : lsBoxUoM 

private async void GetAllUoMForThisItem(string No) 
     { 
      var db = new SQLiteAsyncConnection(DBPath); 


     (I need to clear the content each time an item selected in GridView) 
      UoMCollection.Clear(); 

      var allUoM = await db.QueryAsync("Select * From ItemUoM Where ItemNo = '" + No + "'"); 

      foreach (var _UoM in allUoM) 
      { 
       string strUoM = _UoM.UoM; 

       AddToList(strUoM); 
      } 

      lsBoxUoM.ItemsSource = null; 
      lsBoxUoM.ItemsSource = UoMCollection; 

     } 


private void AddToList(string uom) 
     { 

      UoMCollection.Add(new ItemUoM() 
      { 
       UoM = uom 
      }); 

     } 




-3-- Make a selection in this PopUpBox 

private void lsBoxUoM_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 

      if(lsBoxUoM.SelectedIndex == -1); 

      var Uom = (ItemUoM)lsBoxUoM.SelectedItem; 
      txtBlkUoM.Text = Uom.UoM.ToString(); 

     } 


-4- Close this PopBox after a selection is made and Start from (2) again 


回答

0

lsBoxUoM_SelectionChanged你測試lsBoxUoM.SelectedIndex == -1。這應該是lsBoxUoM.SelectedIndex != -1。並且在txtBlkUoM.Text = Uom.UoM.ToString();之後,您應該將SelectedIndex重置爲-1,以便在用戶再次選擇相同的項目時再次提高選擇更改的事件。

相關問題