.SetFocus不选择整个字段 [英] .SetFocus is not selecting the whole field

查看:53
本文介绍了.SetFocus不选择整个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用作搜索字段的文本框。为了触发搜索,我在文本框上使用了AfterUpdate事件,并且我有一个更符合鼠标的按钮。


按钮的OnClick和文本框的AfterUpdate事件都调用相同的私有子。在该子例程中,我测试结果以查看是否存在匹配,如果没有,我将.SetFocus返回到搜索文本框,以便用户可以重新键入新值。


问题:如果从文本框的OnClick事件调用子例程,则光标将转到字段的开头而不是选择整个字段。


如果从按钮的OnClick事件中调用子例程,则会按照我的意愿选择整个字段。


我确实检查了Access的设置,了解输入字段时该怎么做,并设置为选择整个字段。我最初认为这是因为如果我从文本框的AfterUpdate事件中触发子程序,控件已经具有焦点,所以我尝试将焦点设置在按钮上,然后返回到文本框。触发子程序的任何一种方法都没有变化,所以我把它取回了。


这是我的代码:

展开 | 选择 | Wrap | 行号

解决方案

这是设计的。

您需要的是以下内容:

< span class =codeLinkonclick =Blur(this,this.parentNode.parentNode,getChildren(this),true);>展开 | 选择 | W rap | 行号


< blockquote>如果我在现有记录上,那就有效,但是如果我在新记录上,它仍然将光标放在字段的开头。


Seth:

如果我在现有记录上有效,但如果我在新记录上仍然将光标放在字段的开头。



如果这是一个新记录,那怎么可能不然?你有一个新的记录显示在这个控件中的数据吗?


Z'的代码几乎与我建议的完全相同(我不会用变量来保存 .Value 的长度,并且非常有意义。通常,当切换窗体上的控件(使用Tab键等)时,每个新选择的控件都会完全选择其值。但是,如果您选择了一个已经选择的控件,就像在 AfterUpdate()中通过代码一样,通常不会发生任何事情。


您的选择是要么选择整个内容作为Z'的建议,要么先选择另一个控件然后再回到你想要的那个。 就像您作为运营商一样


如果您确实对此代码有疑问,可以报告吗更明确地回来 - 记住我们只有你选择提供的信息来试图确定发生了什么。


I have a textbox that I use as a search field. To trigger the search, I use both an AfterUpdate event on the textbox and I have a button for those that are more mouse oriented.

Both the button''s OnClick and the textbox''s AfterUpdate events call the same private sub. In that subroutine I test the results to see if there was a match and if not, I do a .SetFocus back to the search textbox so that the user can retype a new value.

Problem: If the subroutine is called from the OnClick event of the textbox, then the cursor goes to the beginning of the field instead of selecting the whole field.

If the subroutine is called from the button''s OnClick event, then the whole field is selected like I want.

I did check Access''s setting for what to do when entering a field and it is set to select the whole field. I initially thought that it was because the control already had focus if I triggered the subroutine from the textbox''s AfterUpdate event, so I tried having it set focus on the button and then going back to the textbox. There was no change for either method of triggering the subroutine so I took it back out.

Here is my code:

Expand|Select|Wrap|Line Numbers

解决方案

That is by design.
What you need is the following:

Expand|Select|Wrap|Line Numbers


That works if I''m on an existing record, but if I''m on a new record it still puts the cursor at the beginning of the field.


Seth:
That works if I''m on an existing record, but if I''m on a new record it still puts the cursor at the beginning of the field.

If this is a new record then how could it be otherwise? Do you have a new record with data showing in this control?

Z''s code is almost exactly as I would have suggested (I wouldn''t have used a variable to save the length of .Value), and makes perfect sense. Generally, when switching controls on a form (using Tab keys etc), each newly selected control has its value fully selected. If you select a control that is already selected, however, as in the AfterUpdate() route through the code, nothing will typically happen.

Your choices are either to select the whole of the contents as Z''s suggested, or to select another control first then come back to the one you want. Just as you would as an operator.

Please, if you actually have a problem with this code, could you report it back more explicitly - remembering we have only the information you choose to give with which to try to determine what''s going on.


这篇关于.SetFocus不选择整个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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