code review please

Hi,
Can anyone shed some light as to why the last line of my code below sets the insertion point at the end of THE WRONG TEXT FIELD??
It sets the insertion point to the end of a textfield called Codefield and not TitleField???

[code] // RETRIEVE THE DATA FROM THE DATABASE
Dim ps As SQLitePreparedStatement = db.Prepare(“SELECT * FROM snippets WHERE Title = ?;”)
ps.BindType(0, SQLitePreparedStatement.SQLITE_TEXT)

// BIND THE SELECTED LISTBOX ROW
ps.Bind(0, MainWindow.Listbox1.cell(MainWindow.Listbox1.listindex,1))
rs=ps.SQLSelect

// CHECK FOR DATABASE ERROR
If db.Error Then
MsgBox("Error: " + Str(db.ErrorCode) + " - " + db.ErrorMessage)

else
If rs.EOF Then
MsgBox “No data found”

Else
  // UPDATE THE TEXTFIELDS
  TitleField.text=rs.field("Title").StringValue
  
  dim s as string = DefineEncoding( rs.field("Code").StringValue , Encodings.UTF8 )
  CodeField.text=s
  
End If

End If

// SET THE INSERTION POINT TO THE END OF THE TITLE FIELD
TitleField.SelStart = Len(TitleField.Text)[/code]

Thank you.

Do you need to do a TitleField.SetFocus first?

Bill - I tried that and it made no difference - that’s why I removed it?
I can’t understand why it’s doing it - that is the only code which is inside the Window’s open event.

Richard are the textfields you are mentioning anyway using the same class or something? I don’t see where else it could be wrong without looking at the project.

I doubt this will change anything, but see if you can separate your code just a bit.

Dim TextFieldLen as Integer =  TitleField.Text.Len
TitleField.SelStart = TextFieldLen

Search on CodeField and see if it is being referenced somewhere else and you are just forgetting about it.

It has to do with being in the Open event, and I can duplicate it with a simple project with 2 textfields on the window. But if you move your code to a button’s action event, it will work fine. I can’t remember the workaround I saw on the forums, but someone posted about it within the last couple of months, I’m pretty sure. I’ll see if I can find it.

You can also move it to the window’s Activate event and it works fine too. You’ll just need to set a boolean that makes sure you only run the code once (you don’t want it running over and over when you switch away from the window and then back to it).

Hey, it was a post you started and I answered I was thinking of! LOL
Insertion Point

Did you ever file a bug report?

Bill,
I must have had this problem before :slight_smile:
I did what you recommended in the other post about the got focus event handler, and it now works as expected.

Thanks. :slight_smile: