收到此错误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 :(得分:0)
您的问题本身包含您的答案,您需要在为其分配新项目源之前清除项目集合,请点击此处 - BuildstreamComboBox.Items.Clear()