2011-04-19 113 views
1

得到這個錯誤Items collection must be empty before using ItemsSource.無效操作異常是未處理

這個錯誤是在這一行中發現:

BuildstreamComboBox.ItemsSource = dz;

代碼:

public void PopulatebuildstreamFromXMLFile() 
    { 
     if (BuildmachineComboBox.SelectedIndex == 0) 
     { 
      ds3.Clear(); 
      ds3.ReadXml(@"C:\GUI\buildermanageremail.xml"); 

      DataView dy = ds3.Tables["buildstream4"].DefaultView; 

      BuildstreamComboBox.ItemsSource = dy; //Sets the collection of items from which to populate 
      BuildstreamComboBox.DisplayMemberPath = "value"; //Sets the path within an item to use for display 
     } 
     if (BuildmachineComboBox.SelectedIndex == 1) 
     { 
      ds3.Clear(); 
      ds3.ReadXml(@"C:\GUI\buildermanageremail.xml"); 

      DataView dz = ds3.Tables["buildstream5"].DefaultView; 

      BuildstreamComboBox.ItemsSource = dz; //Sets the collection of items from which to populate 
      BuildstreamComboBox.DisplayMemberPath = "value"; //Sets the path within an item to use for display 
     } 
    } 

其中ds3的肺癌:

DataSet ds3 = new DataSet();

有人有什麼想法嗎?

+0

請問你BuildstreamComboBox看在XAML?它是否有子元素? – Heinzi 2011-04-19 05:50:54

+0

哦,是的..它確實有以前的物品來源。忘記刪除他們感謝提醒! – jeremychan 2011-04-19 05:53:22

回答

0

你這個問題本身就含有你的答案,你需要明確分配給它一個新的項目源艾克在此之前的項目集合 - BuildstreamComboBox.Items.Clear()