I will preface this question/information with the fact that I am by no means a .NET/VB/Windows programmer. I am supporting legacy code which at times just confounds me as to how it works...sometimes. Like this time.
Details:
- Visual Studio 2008
- Compact Framework 2.0
- Visual Basic Application
- Some libraries in C#, but not pertinent for this question.
In a nutshell, my problem is that I put text/content into a field. And when the field gets focus, the cursor is at the beginning of the field instead of the end of the field. This means that the user cannot edit what is in the field, but just re-type over it.
When searching for solutions, I found a lot of suggestions to SelectionStart. Unfortunately, the fields that I am using aren't setup as textboxes. Or maybe they are at their core, but I don't see that or know how to access it. I have access to a Control. Hopefully that makes sense.
To give the field focus, I have to set Enabled to False for the previous field, and then call Focus() for the field that I've preloaded with content. Like:
Public Structure UDT_CTL
Dim ctl As Control
Dim typ As CTLTYP
Dim Tag As Integer
Dim Text As String
Dim evnSet As Boolean
Dim idctlbase As Integer
End Structure
Public Structure UDT_CTLPAG
Dim nlbl As Integer
Dim npic As Integer
Dim nbtn As Integer
Dim ntxt As Integer
Dim nlblm As Integer
Dim MapidBtnVer() As Integer
Dim MapidBtnHor() As Integer
Dim Ctl() As UDT_CTL
End Structure
Public gCtl As UDT_CTLPAG
gCtl.Ctl(CTL.FIELD2).ctl.Text = tmpVal 'Load content into field
gCtl.Ctl(CTL_MAP.TXT_FIELD1).ctl.Enabled = False ' Disable previous field
gCtl.Ctl(CTL_MAP.TXT_FIELD2).ctl.Focus() 'Set focus on field with content
So... As you can see, I'm not working with the textbox directly. And I'm not sure I have all of the terminology correct.
But, beyond setting focus on the field, how can I move the cursor to the end of the text I set in the field? I'd like the end user to be able to edit what is there, not just re-type over it.
Thank you!!