【问题标题】:Default value for Windows Form Combo box?Windows 窗体组合框的默认值?
【发布时间】:2011-12-21 07:14:16
【问题描述】:

我有一个组合框,其中包含不同的声音值。每当我选择不同的值时,播放器都会播放一次声音。

但问题是,当我启动程序时,在加载表单时,我加载了包含组合框上先前存储的声音值的设置文件,我使用组合框的 SelectedIndex 属性作为默认值。

使用 SelectedIndex 会导致播放器在程序启动时播放一次声音,这在这个意义上有点奇怪。

知道如何选择除了 selectedIndex 之外的默认值吗?因为 selectedIndex 还运行该特定值的后端代码。

【问题讨论】:

    标签: winforms combobox


    【解决方案1】:

    假设播放声音的代码位于您的SelectedIndexChanged 事件处理程序方法中,解决方案是仅将该处理程序方法附加到事件之后您已设置默认选定索引.

    例如:

    private void DoLoad()
    {
      // Set the data source, and the default selection
      cbox.DataSource = YourDataSource;
      cbox.SelectedIndex = YourLastSelIndex;
    
      // Then attach the event handler method.
      cbox.SelectedIndexChanged += YourSelectedIndexChanged;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-06-17
      • 1970-01-01
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 2012-07-25
      相关资源
      最近更新 更多