Results 1 to 3 of 3

Thread: Prevent Text Box getting focus?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Prevent Text Box getting focus?

    It is awkward when the Lost Focus event is used to trigger processing of user input for an application which also changes the text programmatically. The Lost Focus subroutine gets invokes when I do not need it.

    I know the program can do txtBoxA.Datachanged = False and have the Lost Focus Subroutine check for data being changed. It still makes for awkward code, and sometimes an application behaves strangely because a Text Box gets and loses Focus in a manner I did not anticipate.

    Is there a clean way to avoid this problem? It would be nice if there was some way to change the data in a Text box without having it get focus. I suppose this is impossible.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    PowerPoster Arc's Avatar
    Join Date
    Sep 2000
    Location
    Under my rock
    Posts
    2,336
    Try using the validate event instead... You can set the casuesvalidation to = true or false

    If it is set to true then any code you have in the validate event will fire when that control loses focus.. otherwise it won't.

    It's better than the lost/got focus events and casues less confusion.
    -We have enough youth. How about a fountain of "Smart"?
    -If you can read this, thank a teacher....and since it's in English, thank a soldier.


  3. #3
    Addicted Member glyptar's Avatar
    Join Date
    Sep 2002
    Location
    The Netherlands
    Posts
    138
    You can change the data in a textbox without it getting focus quite easily.

    VB Code:
    1. Text1.Text = Text1.Text & " adding some text"

    if you put that in another sub or function or whatever, it wont fire the gotfocus event of the textbox.

    Hope it helps
    Glyptar

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width