【问题标题】:Clear comboBox of one radioButton when another radioButton is activated激活另一个单选按钮时清除一个单选按钮的组合框
【发布时间】:2020-02-28 12:04:05
【问题描述】:

我在第一个 radioButton 中有两个 RadioButton 和一个组合框,在另一个 radioButton 中有一个文本框。

当我激活第一个 RadioButton,即相应的 ComboBox 时,它会被启用。现在,当我选择另一个 RadioButton 时,之前选择的 ComboBox 中的信息应该会清除,但不会被清除。 文本框也是如此。

我正在为这个 wpf 应用程序使用 c# 语言和 Visual Studio 2013 版本。

为了在组合框中从 FileExplorer 加载驱动器名称,我使用了此代码-

DriveInfo[] listDrives = DriveInfo.GetDrives();

            foreach (DriveInfo drive in listDrives)
            {
                cmbDrives.Items.Add(drive.Name);
            }

这里 cmbDrives 是组合框的名称

我试过这个代码-

if (radioButton1.IsChecked == true)
            {
                textBox.Text = "";
            }

if (radioButton2.IsChecked == true)

            {                   
                cmbDrives.Text = "";

            }

但它不起作用

【问题讨论】:

  • 您是要从cmbDrives.Items 中删除所有项目以使列表为空还是只是将选择重置为第一个项目?Clear 可能是您想要的。
  • 我正在尝试删除所有项目,使其显示为空。无法为组合框使用 Clear 属性,因为它在我的版本中不可用
  • 抱歉,我引用了 .NET 文档,而不是 WPF。 cmbDrives.Items.Clear() 支持很久了。

标签: c# wpf combobox radio-button


【解决方案1】:

你可以使用 items.clear,但我想你只是不想显示任何东西,如果选择了某些东西,尝试 selecteditem=null,它可能会工作

【讨论】:

  • 可能选择文本?
猜你喜欢
  • 2014-12-12
  • 2016-09-24
  • 1970-01-01
  • 1970-01-01
  • 2013-06-28
  • 2017-07-19
  • 1970-01-01
  • 2019-05-24
  • 2021-11-17
相关资源
最近更新 更多