Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF ComboBox clear

Tags:

wpf

I have Two radio buttons. If i check first radio button The below data will populate in the combobox. After that i will check another radio button, i want to clear the combo box values.

<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" />
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;
    }

}

1 Answers

Are you asking for

cmbEmpType.Items.Clear();

This should empty your combo.

like image 116
gcores Avatar answered Apr 19 '26 12:04

gcores



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!