什么是最佳的方式执行一个选择选项,在Windows形式?我要强制执行的单个选择从清单,开始与默认值。

这似乎是一种组合框会是一个好的选择,但是没有一种方法指定一个非空缺省值?
我可能只是将它设置在代码在一些适当的初始点,但我觉得我好像失去了一些东西。

有帮助吗?

解决方案

如果你只想要一个答案从基,然后一个选择按钮的控制将是你最合适或者你可以使用的组合框如果你会有很多的选择。设定缺省值,只是添加该项目的组合框收集和集的属性或SelectedItem该项目。

这取决于如何很多选择你看,你可以使用一个列表框,与SelectionMode性集MultiSimple,如果将是多个选择或者你可以使用框控制。

其他提示

你应该能够刚刚成立的组合框。属性酒店有什么你想的默认值。

http://msdn.microsoft.com/en-us/library/system.windows.forms.combobox.selectedindex.aspx

使用 组合框。SelectedItem属性 财产之后,项目已经插入以选择默认项目。

你也可以考虑使用 选择按钮 控制强制执行选择的一个选项。

你可以使用一个组合框的 DropDownStyle 的位置向下拉列表和属性为0(或什么的默认项目)。这将力总是有一个项目从清单中选择。如果你忘记了做到这一点,用户可能只需要输入其他东西进入编辑框部分--这将是坏:)

如果你给用户的一个小单的选择,然后坚持无线电按钮。但是,如果你想要使用框动态或长名单。设定的风格,以下拉列表.

private sub populateList( items as List(of UserChoices))
   dim choices as UserChoices
   dim defaultChoice as UserChoices 

   for each choice in items
      cboList.items.add(choice)
      '-- you could do user specific check or base it on some other 
      '---- setting to find the default choice here
      if choice.state = _user.State or choice.state = _settings.defaultState then 
          defaultChoice = choice
      end if 
   next 
   '-- you chould select the first one
   if cboList.items.count > 0 then
      cboList.SelectedItem = cboList.item(0)
   end if 

   '-- continuation of hte default choice
   cboList.SelectedItem = defaultChoice

end sub
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top