激活另一个单选按钮时清除一个单选按钮的组合框
Clear comboBox of one radioButton when another radioButton is activated
我在第一个单选按钮内有两个单选按钮和一个组合框,在另一个单选按钮内有一个文本框。
当我激活第一个 RadioButton 时,相应的 ComboBox 被启用。现在,当我选择另一个 RadioButton 时,先前选择的 ComboBox 中的信息应该会被清除,但不会被清除。
文本框也是如此。
我正在为这个 wpf 应用程序使用 c# 语言和 visual studio 2013 版本。
为了在 comboBox 中从 FileExplorer 加载驱动器名称,我使用了这个代码-
DriveInfo[] listDrives = DriveInfo.GetDrives();
foreach (DriveInfo drive in listDrives)
{
cmbDrives.Items.Add(drive.Name);
}
这里的cmbDrives是comboBox的名字
我试过这段代码-
if (radioButton1.IsChecked == true)
{
textBox.Text = "";
}
if (radioButton2.IsChecked == true)
{
cmbDrives.Text = "";
}
但它不起作用
你可以使用items.clear,但我想你只是想什么都不显示,如果选择了某些东西,试试selecteditem=null,它可能有效
我在第一个单选按钮内有两个单选按钮和一个组合框,在另一个单选按钮内有一个文本框。
当我激活第一个 RadioButton 时,相应的 ComboBox 被启用。现在,当我选择另一个 RadioButton 时,先前选择的 ComboBox 中的信息应该会被清除,但不会被清除。 文本框也是如此。
我正在为这个 wpf 应用程序使用 c# 语言和 visual studio 2013 版本。
为了在 comboBox 中从 FileExplorer 加载驱动器名称,我使用了这个代码-
DriveInfo[] listDrives = DriveInfo.GetDrives();
foreach (DriveInfo drive in listDrives)
{
cmbDrives.Items.Add(drive.Name);
}
这里的cmbDrives是comboBox的名字
我试过这段代码-
if (radioButton1.IsChecked == true)
{
textBox.Text = "";
}
if (radioButton2.IsChecked == true)
{
cmbDrives.Text = "";
}
但它不起作用
你可以使用items.clear,但我想你只是想什么都不显示,如果选择了某些东西,试试selecteditem=null,它可能有效