记住多选列表框选择 [英] Remembering multi-select list box selections

查看:63
本文介绍了记住多选列表框选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个未绑定的多选列表框,该列表框是从显示建筑类型的查询中填充的。我在表单上有两个复选框,当一个或另一个设置为true时,它会更改列表框中的项目,一次只能选中一个复选框。选中后,一个复选框将显示除多家庭以外的所有类型的建筑物,而另一个复选框仅显示多家庭建筑物。


我的问题是,如果用户选择列表框中的项目,然后切换其中一个复选框,则由于更改可供选择的项目而重置列表框。挑战在于在切换其中一个复选框之前记住用户在列表框中选择的内容。在大多数情况下,我的代码可以处理这个问题,但只有当一个复选框打开或关闭而不是任何一个或复选框时它才有效。我最终得到一个错误,指出我的ReStoreListSelection函数中的运行时错误9:下标超出范围。我怀疑这与我的数组有关,并且在调试时我发现正确的值没有被传递回我想要的列表框,具体取决于选择了哪个复选框。我无法弄清楚我需要在代码中进行哪些更改才能实现这一点。


我在每个复选框更新后调用一个模块中的函数来处理这个场景。我的代码如下:

I have an unbound multi-select list box that is populated from a query that displays types of buildings. I have two check boxes on the form that change the items in the list box when one or the other is set to true, only one check box can be selected at a time. One check box, when selected, displays all types of buildings except for multi-family, while the other check box displays only multi-family buildings.

My problem is if the user selects items in the listbox and then toggles one of the check boxes, the listbox is reset because of the changing of the items available to select. The challenge is to remember what the user selected in the listbox prior to toggling either one of the check boxes. For the most part, my code works to handle this but it only works when one checkbox is toggled on or off and not either or checkbox. I end up with an error that says run-time error 9: subscript out of range in my ReStoreListSelection function. I suspect this has to do with my array and upon debugging I discovered that the correct value is not being passed back to the listbox that I desire depending on which checkbox is selected. I can''t figure out what I need to change in my code to make this happen.

I call a function from a module in the after update of each checkbox to handle this scenario. My code is as follows:

展开 | 选择 | Wrap | 行号

推荐答案

您的复选框,因为已选中或者,充当选项组。这就是我使用Option组功能的原因。实际上,您只能有一个复选框。当检查列表框显示内容时,取消选中列表框时显示其他内容。


在附件中,您可以看到基于选项组功能的解决方案。

代码为:
Your check boxes, because are checked alternatively, act as an option group. It is why I use the Option group feature. In fact you can have only one check box. When check the list box show something, when un-check the list box show other thing.

In the attachment you can see a solution based on Option Group feature.
The code is:
展开 | 选择 | Wrap | 行号


感谢您的回复。这很好用。但是,我没有使用选项组,因为我希望能够取消选择这两个选项。表单实际上是一个搜索表单,当我单击搜索按钮时,将根据选中的复选框创建不同的SQL,但不同的项目将显示在列表框中,具体取决于我们已经建立的复选框。那么如果选中多族复选框,则列表框会显示多家庭建筑物。如果选中租约复选框,则常规建筑物将显示在列表框中,但会在搜索点击事件中创建SQL,以仅显示具有租约的建筑物。如果未选中任何复选框,则相同的regalr建筑物仍​​会显示在列表框中,只有搜索点击事件中生成的SQL才会抓取已售出的建筑物。如果用户在复选框之间来回切换,只需要记住所有SQL的东西。


任何想法?
Thanks for your reply. That works pretty good. However, I didn''t use an option group because I would like to be able to unselect both options. The form is actually a search form and when I click on the search button, different SQL is created depending on which check box is selected but different items appear in the listbox depending on which check box is selected like we already established. So what happens is if the multi-family check box is selected, the listbox displays multi-family buildings. If the lease check box is selected, regular buildings appear in the listbox but SQL is created on the search click event to show only those buildings with leases. If no checkbox is selected, the same regualr buildings still appear in the listbox, only the SQL that is generated in the search click event grabs buildings that have sold. All the SQL stuff works, just need to remember the selections if the user toggles back and forth between check boxes.

Any ideas?


I我在想,如果我添加第三个选项来构建销售并将其设为默认值,该怎么办?这可以解决我的问题。
I was thinking, what if I added a third option for building sales and make this the default? This may solve my problem.


这篇关于记住多选列表框选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆