WPF ComboBox清楚

3 wpf

我有两个单选按钮.如果我检查第一个单选按钮以下数据将填充在组合框中.之后,我将检查另一个单选按钮,我想清除组合框值.

<RadioButton Height="29"
             HorizontalAlignment="Left"
             Margin="143,193,0,0" Name="rdoEmployee" VerticalAlignment="Top" Width="61"
             FontSize="20"  Checked="rdoEmployee_Checked" GroupName="rdoEmployee/>

<RadioButton FontSize="20" Height="20" Margin="228,193,0,0" Name="rdoPA" 
             VerticalAlignment="Top" HorizontalAlignment="Left" Width="49"  
             Checked="rdoPA_Checked" GroupName="rdoEmployee />

<ComboBox HorizontalAlignment="Left" Margin="142,235,0,240" 
          Name="cmbEmpType" Width="200" FontSize="16" />
Run Code Online (Sandbox Code Playgroud)
EmployeeTypes _ET = new EmployeeTypes();
DataRowCollection drc = _ET.EmpTypeTable.Rows;
foreach (DataRow r in drc)
{
    ComboBoxItem item = new ComboBoxItem();
    item.Tag = r["EmpTypeID"];
    item.Content = r["EmpTypeName"];

    cmbEmpType.Items.Add(item);

    if (cmbEmpType.Items.Count > 0)
    {
        cmbEmpType.SelectedIndex = 0;
    }

}
Run Code Online (Sandbox Code Playgroud)

gco*_*res 12

你在问

cmbEmpType.Items.Clear();
Run Code Online (Sandbox Code Playgroud)

这应该清空你的组合.