简体   繁体   English

Windows UI设计-组合框

[英]Windows UI Design - The Combo Box

Until today I had not realized there was a difference between a list-box (like the HTML Form control drop-down selection box) and a "combo box" which is a combination of the list-box and the text-entry control. 直到今天,我还没有意识到列表框(例如HTML Form控件的下拉选择框)和“组合框”之间的区别,该组合框是列表框和文本输入控件的组合。 So the ComboBox allows the user to enter in a new value and if programed to do so, will append the value to the list of values it displayed when clicked on. 因此,ComboBox允许用户输入新值,并且如果被编程为这样做,则将其添加到单击时显示的值列表中。

Having just read a few books on interface design, I think that while the concept sounds cool, and will ultimately save me having to make another interface to 'add' choices, I feel like it may be confusing to less-than-advanced users who may miss the fact that you could enter values in this way. 刚刚阅读了几本关于界面设计的书,我认为虽然这个概念听起来很酷,并且最终将使我免于不得不为“添加”选择创建另一个界面,但我觉得这可能会使不那么高级的用户感到困惑可能会错过您可以通过这种方式输入值的事实。

Does anyone have any opinions on the use of the combo box and its pro/con vis-a-vis good UI design principles? 有人对组合框的使用及其相对于良好的UI设计原则有何看法? My application should be used by many people of all age groups. 所有年龄段的人都应该使用我的应用程序。

Matt, here are some details that might be of use to you, in case you proceed with it. 马特,如果您继续进行操作,以下是一些可能对您有用的细节。

I have used combo boxes in a couple of places on my forms in exactly the way you have mentioned. 我已经按照您提到的方式在表单的几个地方使用了组合框。

In addition to the adding facility, you can also give edit & delete options to the user where the user can edit/ rename and delete the combo entries. 除了添加功能外,您还可以为用户提供编辑和删除选项,用户可以在其中编辑/重命名和删除组合条目。 However, you need to be extremely careful with the selected index when providing this feature as it can get pretty messy. 但是,在提供此功能时,您必须格外小心所选索引,因为它可能会变得非常混乱。

In my case, I have the following three items to take care of all the above mentioned functionality: 就我而言,我有以下三个项目来处理上述所有功能:

  1. Combo box with DropDownStyle = DropDown DropDownStyle = DropDown的组合框
  2. Save button 保存按钮
  3. Delete button 删除按钮

Functionality is as follows: 功能如下:

In the combo box in addition to the items already saved by the user, I have an item --New-- at the top. 在组合框中,除了用户已经保存的项目以外 ,我的顶部还有一个--New--项。 When the user has to edit/ rename an item, he should select the item from the combo, type the new name in the combo and then click Save. 当用户必须编辑/重命名项目时,他应该从组合中选择该项目,在组合中键入新名称,然后单击“保存”。 If the user wants to add a new item, he should select --New-- from the combo, type in the name in the combo (this will overwrite --New--) and click Save If the user needs to delete an item, he should simply select the item and click on Delete 如果用户要添加新项目,则应从组合中选择--New--,在组合中键入名称(这将覆盖--New--),然后单击“保存”。如果用户需要删除项目,他只需选择该项目,然后单击“删除”

I have implemented the SelectionChangeCommitted event rather than the SelectedIndexChanged , as the latter fires event if the selected index is set through code, whereas the former only when user is selecting an item in the combo box from the screen. 我实现了SelectionChangeCommitted事件,而不是SelectedIndexChanged事件,因为如果通过代码设置了选定的索引,后者将触发事件,而前者仅在用户从屏幕上的组合框中选择一个项目时才触发。

In addition, I have maintained a form level variable called _selectedComboID which stores the id of the currently selected combo item. 此外,我还维护了一个名为_selectedComboID的窗体级别变量,该变量存储当前所选组合项的ID。 It gets set in the SelectionChangeCommitted event handler. 它在SelectionChangeCommitted事件处理程序中设置。 This is because, if you have to rename an entry in the combo, you will first select it. 这是因为,如果必须在组合中重命名条目,则将首先选择它。 At that time the selectedIndex is correct (the one you have selected). 那时selectedIndex是正确的(您选择的那个)。 Then since you need to rename it, you will edit the combo text and click Save. 然后,由于需要重命名,因此您将编辑组合文本并单击“保存”。 However, since you have edited the name, it now messes with the selected index. 但是,由于您已经编辑了名称,因此它现在与所选索引混淆。 So I save it in a variable before hand when user makes the selection. 因此,当用户进行选择时,我会事先将其保存在变量中。

In the Save method, I have checked if _selectedComboID is same as the ID for --New--. 在Save方法中,我检查了_selectedComboID是否与--New--的ID相同。 If yes, the insertion code is fired, else the edit code. 如果是,则触发插入代码,否则触发编辑代码。 In both cases, you need to check that the name chosen by the user doesn't already exist, in addition to other validations. 在这两种情况下,除了其他验证之外,您还需要检查用户选择的名称是否不存在。

If you are setting Sorted = true for your combo box, it is very important to use SelectedItem throughout your code rather than SelectedValue. 如果您为组合框设置Sorted = true ,则在整个代码中使用SelectedItem而不是SelectedValue非常重要。 This is because when you set sorted as true for a combo box, it messes up the selected values. 这是因为当您将组合框的排序设置为true时,它会使选定的值混乱。 You can refer to my post on Setting selected item in a ListBox without looping for details. 您可以参考我的文章“在列表框中设置所选项目而无需循环”以获取详细信息。

Wow, that was huge!!! 哇,好大!!! Hope it helps :) 希望能帮助到你 :)

Pro: Easy to add new options (for the user) 专业版:易于添加新选项(针对用户)

Con: Easy to add new options (especially later when you are talking about data clean up, duplicate entries. Basically the same flaw when you allow free text entry). 缺点:易于添加新选项(尤其是稍后谈论数据清理,重复条目时。在允许自由文本输入时基本上是相同的缺陷)。

This page from kdedevelopers.org was a good read. 来自kdedevelopers.org的页面非常好阅读。 Let me see if I can summarize. 让我看看是否可以总结一下。

Listbox 列表框

+ Good for showing a short list +适合显示简短清单
+ Shows most options at all times + It follows that it works great when the user can choose multiple options from a list + 始终显示大多数选项 +因此,当用户可以从列表中选择多个选项时,该选项非常有用
- Listboxes do not support "adding" to the list of choices intuitively -列表框不支持直观地将“添加”到选项列表

Combobox 组合框

+ Good for long lists. +适合长名单。 It prevents big lists from taking up too much space on the UI. 可以防止大列表占用过多的UI 空间
- Shows one selected option only - the choices are hidden unless you click on the dropdown button. -仅显示一个选定的选项-除非单击下拉按钮,否则选项将被隐藏
+ Allows the feature of users being able to add to the list of choices . +允许用户能够添加到选项列表中的功能 Usually has a style property, where you can customize eg prevent 'addition' in case you don't want it. 通常具有样式属性,您可以在其中进行自定义,例如在不需要的情况下阻止“添加”。

Others feel free to add on. 其他人可以随意添加。 Humble suggesion: hopefully via comments. 谦虚的建议:希望通过评论。 Upvoted comments can then moved into the post text by anyone. 然后,任何人都可以将已评论的评论移到帖子文本中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM