Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to display end of memo field and put cursor at end?
Message
From
24/01/2004 11:06:24
 
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00869717
Message ID:
00870236
Views:
18
Well, that was harder than I expected. This was my original goal.

How can I display the text at the end of the memo field and position the cursor at the end of text?

I started by looking up (as suggested by Sergey):

How to Force Scroll Bars in Edit Box to 'end' of control Message #810707 from Chuck Mautz.

I assume this works fine but I wanted the control to exhibit the behavior on entry while this is a function that would be called remotely to move the cursor to the end of text.

So next I looked at the Add-only Editbox at http://www.glrsoftware.com/download.asp#Add_Only_editbox.zip

This is a neat bid of coding from Greg Reichert but it was really more than I needed. My users like to be able to edit old notes. I've tried to convince them that this is a little dangerous but they are adamant that they want to be able to do this.

But somewhere in Greg's code was the secret of placing the cursor at the end of the text. I browsed his ADDONLY.VCX and realized that his THIS.SELSTART = LEN(THIS.VALUE) line was in the WHEN method (not the GetFocus method).

Ah ha! I took this key insight and made up a little editbox that worked just the way I wanted. I thought I was home free.

But when I put this same code in my application it still didn't work.

After much farting around I realized that something was turning on the 'K' format value in my editbox causing the control to select all the text when the control gets focus. Since I was also setting the cursor to the end in the WHEN method (which sets SELLENGTH to zero) the results were confusing and inconsistent.

Turned out that some Codebook/VFE code was setting the EditBox format property to 'K' if there was no other value in the DBCX. I told it not to do that for baseclass EDITBOX.

Finally my edit box worked beautifully. Regardless of whether I clicked within the editbox, or clicked on the sliders, or tabbed into the editbox, the cursor went to the end of text which was displayed in the editbox.

So here is how to put the cursor at the end of existing text in a memo field and never select all of the text on entry:

1) Make sure the EDITBOX.SELECTONENTRY property is FALSE.

2) Make sure the EDITBOX.FORMAT property is empty at design time.

3) Make sure the EDITBOX.FORMAT property is empty at run time.

4) Place this code in the EDITBOX WHEN method:
     THIS.SELSTART = 99999
     RETURN .T.
That should do it.

Thanks to everyone who answered!

Peter


KEYWORDS: MEMO FIELD EDIT BOX EDITBOX TEXT END CURSOR SCROLL BAR SCROLLBAR
Peter Robinson ** Rodes Design ** Virginia
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform