根据其他值禁用复选框 [英] Disable Check Box Based on Other Values

查看:126
本文介绍了根据其他值禁用复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相对简单的连续表格.有一个不可见的复选框,我们称它为弗兰克.

I have a relatively simple Continuous Form. There is an invisible Check Box, let's call it Frank.

第二个复选框(Ralph)可能为True或False.还有一个带有日期(RalphDate)的文本框.

There is second Check Box (Ralph) which may be True or False. There's also a text box with a date (RalphDate).

如果Frank为True,那么我不希望用户能够更改Ralph或RalphDate,无论已经存在什么.

If Frank is True, I don't want the user to be able to change Ralph or RalphDate, regardless of what is already there.

现在,RalphDate很容易,因为我只使用条件格式来检查Frank的值,该值可以启用或禁用RalphDate.此选项不适用于复选框.

Now, RalphDate is easy in that I just use a Conditional Format to check the value of Frank which either enables or disables RalphDate. This option is not available for a Check Box.

我现在陷入困境,因为使用某些Visual Basic会根据遇到的第一个Frank值将所有Ralph框的状态设置为相同.因此,问题是,如何基于Frank复选框为True来仅禁用关联的Ralph复选框?

I'm now stuck, because using some Visual Basic sets the state of all the Ralph boxes the same based on the value of the first Frank value it comes across. The question therefore, is how do I disable only the associated Ralph Check Box based on the Frank Check Box being True?

推荐答案

解决方案1 ​​

  • 更新ckRalph的Locked属性而不是Enabled.
  • 在表单的OnCurrent()事件处理程序中执行此操作.
  • Update the Locked property instead of Enabled for ckRalph.
  • do that in the OnCurrent() event handler for the form.

Locked属性将防止在没有视觉提示的情况下进行更改. 这应该照顾到功能部分,即使在外观上仍启用外观复选框,也无法对其进行更改.

The Locked property will prevent changes without visual cue. This should take care of the functional part, even though visually the checkbox will still look enabled, it can't be changed.

解决方案2

另一种方法是通过执行以下操作来模拟复选框:

Another way is to simulate the checkbox by doing this:

  • 使用文本框,将其命名为fakeckRalph;把它做成一个小方块.
  • 使其记录源属性类似于"=getstate()"
  • 创建一个getstate函数,其功能类似于:

  • use a textbox, call it fakeckRalph; make it a small square.
  • make its record source property something like '=getstate()'
  • create a getstate function that does something like:

Public Function GetState() as string
    GetState = iif(ckRalph, "V", " ")
End Function

我建议使用符号字体和字符使刻度线在其框中显示更好.
因此,现在,如果您的 Ralph 为true,则该复选框将显示勾号,否则为空.

I suggest using a symbol font and a character to make the tick appear better in its box.
So now, if your Ralph is true, the checkbox will display the tick and if not, it will be empty.

要完成此技巧,请在 Franck 为true时在文本框上使用条件格式将其禁用.
为了使点击更加逼真,还可以将光标更改为手形指针.

To complete the trick, use conditional formatting on the textbox to disabled it when Franck is true.
To make the clicking more realistic, also change the cursor to the hand pointer.

最后需要做的是从我们的fakeckRalph文本框中连接OnClick事件,以便我们可以切换Ralph的状态并正确显示它:

The last things that's needed is to wire the the OnClick event from our fakeckRalph textbox so that we can toggle the state of Ralph and display it properly:

Private Sub OnClick()
    Ralph = Not Ralph
    fakeckRalph.Requery
End Sub

我已经使用了类似的技术来显示连续表单上的记录是被锁定(使用了来自Windings字体之一的蓝色挂锁符号)还是可删除的,带有可以单击的大红色十字:

I've user similar techniques to show whether a record on a continuous form was locked (used a blue colour padlock symbol from one of the Windings fonts) or deletable, with a big red cross that could be clicked:

图像2 http://img9.imageshack.us/img9/6296/sshot2do5 .png 图片1 http://img8.imageshack.us/img8/4997/sshot1ya5.png

这篇关于根据其他值禁用复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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