Hi,
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
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.
Dave and Jeremy, the “SelLength” idea unfortunately didn’t work
The only code I have in the Window.Open event is as follows:
[code]// SET A FLAG TO INDICATE A WINDOW IS OPEN
Stats1.AnyOpenWindows = true
// POPUATE THE EDIT TEXTFIELDS
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)
end
TextField1.SelLength=0
TextField1.SelStart = TextField1.Text.Len[/code]
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.
Richard, I see the same behavior you do. I just tested it and in the window.open 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.
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 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.
Bill,
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