Insertion Point?

I have an edit window which populates a TextField with a string of unknown length.
I am using the code below to try to set the insertion point to THE END of the text, but my code is simply selecting all of the text in the TextField?

TextField1.SelStart = TextField1.Text.Len

I have looked at the Language Reference, but the SelStart was the nearest thing I could find.
Could someone please advise me?

That’s very strange. What OS? Is the stated code the only initialization code? For me, the above snippet works fine (OS X).

Edit: Um, never mind about the OS question, I didn’t notice it was in Targets > OS X :slight_smile:

What I would do is create a sample project w/a text area, static text in it and see if you can use your method above. If that works, start simplifying your method in your actual program until things start working.

Try setting SELLENGTH=0 before setting SELSTART

Dave and Jeremy, the “SelLength” idea unfortunately didn’t work :frowning:

The only code I have in the Window.Open event is as follows:

Stats1.AnyOpenWindows = true

Dim i as integer
i = Stats1.List.ListIndex
if i>= 0 then
TextField1.Text = Stats1.List.Cell(i,0)
TextField2.Text = Stats1.List.Cell(i,1)
TextField1.SelStart = TextField1.Text.Len[/code]

Where is the text being inserted into the text field?

When a user selects a row in the ListBox and then presses the edit button - the edit window opens up and populates 2 TextFields from the 2 columns in the Listbox.

Seems that the TextField1.SelStart = TextField1.Text.Len should be executed after you populate the field. In the Open event, the text field will not have any content.

Isn’t that exactly what my code above is doing?
Upon the opening of the window, the 2 textfields are populated and then the insertion point is set?

Or am I going mad :slight_smile:

Richard, I’m sorry! I totally misread that!

I’d simplify… Comment some of that code out and do:

TextField1.Text = "Hello World"
TextField1.SelStat = TextField1.Text.Len

and see if that works. If so, use the debugger w/your original code and start working through things.

Richard, I see the same behavior you do. I just tested it and in the event the text field in my example does have content, text.len gives the correct value, but all of the text is being selected. If I do the SelStart in a button, then it works as expected. That stinks.

Also, if I do MsgBox str(textfield1.text.len), it gives the right number and then does the selstart correctly. Take the MsgBox out and it selects all the text again.

Cool - so at least I am not going mad :slight_smile: :slight_smile:
So is that a bug? And any ideas to circumvent it would be greatly welcomed.

I agree Bill - it is stinkier than 10 stinky things in the stinkiest thing competition :slight_smile:

Just a thought, what happens if you do something like:

TextField1.SelStart = TextField1.Text.Len TextField1.SelLength = 0 TextField1.SetFocus()

Guy - nothing changes :frowning:

In the textfield’s “GotFocus” event, put “me.SelStart = me.Text.len”. In your event, just put TextField1.SetFocus.

If you add to your Window.Activate:

TextField1.SelStart = TextField1.Text.Len

Then it acts as you wish. I must admit, my first test was done on TextArea. With a TextField it acts as you say. Will that work in your case? Maybe a work around until things get fixed in Xojo. I’d file a bug report.

I agree with Jeremy, file a bug report.

Jeremy - that worked perfectly!
Thank you.

I will file a bug report as soon as I find out how to :slight_smile:

I don’t know what your software is/does, but I know if I have a textfield active in a window and then switch away to something else, I get really annoyed if it changes focus when I come back to that window. You might want to think about that.

I just tested and if the user begins to type in a textfield, and then clicks on the main window - nothing happens as the edit window is set to movable modal.

If the user clicks on the desktop or a finder window and the re-clicks on my app, the user can continue typing in the textfield he originally left. Is that what you were referring to - if so - all seems ok.

Ah - I have just noticed however, that when returning, although the user can continue to type - the text he previously typed is selected and therefore, upon commencement of typing, the previous text is deleted :frowning: