2011-04-19 61 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()