如何制作组合框使某些项目无法选择? [英] How to make a combobox make certain items not be selectable?

查看:79
本文介绍了如何制作组合框使某些项目无法选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过SQL链接到表的组合框。该表有标准的主键(自动编号)和文本字段。


有3条记录:

I have a combobox linked by SQL to a table. The table has standard Primary Key (Autonumber) and text field.

There are 3 records:

展开 | 选择 | 换行 | 行号

推荐答案

我认为只要在组合框的rowsource的条件中添加适当的Where子句,它就会起作用。绑定数据项的值将显示在文本框中,但是当您单击以浏览其他条目时,您将看到rowsource返回的内容。


如果绑定值不是RMT他们可以选择RMT吗?如果是这种情况,则必须根据绑定数据项的值动态构建行源字符串,if =" RMT"那么rowsource =一件事,如果<>"" RMT"那么rowsource =其他东西。


Jim
I think it will work if you just add the appropriate Where clause to the criteria of the rowsource of the combo box. The value of the bound data item will show in the text box but when you click to browse other entries you will see what the rowsource returns.

If the bound value is not "RMT", are they allowed to choose RMT? If that is the case then you will have to dynamically build your rowsource string based on the value of the bound data item, if ="RMT" then the rowsource = one thing, if <>"RMT" then the rowsource =something else.

Jim


我已经尝试过设置where子句来排除一些记录只是给出一个空白字段我使用这些值(因为我显示表的第二列,第一列是主键)


我自己找到了解决方案。我将一个文本框放在组合框的正上方,这样只有组合框的下拉可见,其控制源通过左连接被拉入表单的记录源。我完全禁用文本框,并使用表单当前事件来决定是否启用组合框。它是一个黑客。但它确实有效。
I have allready tried just setting the where clause to exclude some records simply gives a blank field when i use those values (Since im displaying the second column of the table, the first column being the primary key)

I did find a solution myself. I place a textbox directly above the combobox, in such a way that only the dropdown of the combobox is visible, the controlsource of which is pulled into the recordsource of the form, by a left join. I disable the textbox completely, and use the forms Current event to decide whether or not to enable the combobox. Its a "hack" but it works.


这是一个很好的解决方案SmileyCoder。我之前遇到过类似的问题。


您还可以将Form_Lode例程中ComboBox的行源设置为Table,允许任何项目可见。然后在ComboBox_Click例程中将行源设置为查询。


只有问题是如果用户决定更改ComboBox值,他们将无法将其更改回来原来的价值。
Thats a good way around it SmileyCoder. I have had a similar issue before.

You could also set the row source for the ComboBox in Form_Lode routine to the Table allowing any items to be visible. Then set the row source to the query in the ComboBox_Click routine.

Only issue there is that if a user decides to change the ComboBox value they won''t be able to change it back to its original value.


这篇关于如何制作组合框使某些项目无法选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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