CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 1999
    Posts
    7

    selecting text in textbox, something different

    Hi everyone,
    I am looking for a way to select text in a text box without having to put this

    Text1.SelStart = 0
    Text1.SelLength = Len(Text1)

    into every textbox focus event. I have over a one hundred textboxes. That is a lot. Sure I could put it in a public sub and then call that in every focus event but still the same inherent problem - - 100+ textboxes. whehh. I am looking instead for something that only has to be declared once when the form loads. I am new to this. I guess it would be some kind of API call?
    Any help or direction would be great. Thanks

    Harold


  2. #2
    Join Date
    Jul 1999
    Posts
    145

    Re: selecting text in textbox, something different

    Even if you did use an API call (check the SDK for the text control) you would still have to call it a hundred times. You can set them all nearly at once by iterating through the form's??
    controls collection then use a statement like 'If TypeOf cntrl Is Textbox then ' and insert your code you posted here.<==not sure if it would work but trying to give you some ideas...


  3. #3
    Join Date
    Jul 1999
    Posts
    145

    Nevermind, Dumb idea

    The textbox has to have focus to have its text selected, just tried it out. Doh!


  4. #4
    Guest

    Re: selecting text in textbox, something different

    write the code(as u mentioned Above) in the gotfocus event and made this an activex control use it anywhere


  5. #5
    Join Date
    Sep 1999
    Posts
    11

    Control Array's

    If you make your Textboxes into a Control array (Give all your Textboxes the same name) then you can Select your TB's text like this.

    For A = 0 to 99
    Text(A).SelStart=1
    Text(A).SelLength=5
    Next

    And That's a WHOLE Lot simpler than doing 100's of those statements... (But you'll have to Rename/Remake your TB's (Textboxes)

    -Ximmer


  6. #6
    Guest

    Re: selecting text in textbox, something different

    Mikesc,

    Thanks. Yes, 'If typeof control is textbox' works. Only have to call that function with one line. That is what I had decided to do after I posted. I had contempleated the idea before but thought I would still see if possible another way. However, Ximmer had a great idea bout making all the textboxes a control array. I think that could be useful. 'preciate the help

    Harold


  7. #7
    Join Date
    Jul 1999
    Posts
    145

    Re: selecting text in textbox, something different

    Sorry about my lapse of judgement yesterday. Ximmer's idea would work but not the code. If you got the textbox array set up, just put your code in the GotFocus event. It'll select the text in any textbox in the array, when, of course, the box enters focus.


  8. #8
    Join Date
    Sep 1999
    Posts
    202

    Re: selecting text in textbox, something different

    Maybe you can use timer:
    http://www.**************/Item.asp?PageID=TipBank&ID=82

    Good luck!


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

Featured