move to the end of a listbox

Started by Shawn Anderson, October 22, 2009, 04:13:54 PM

Previous topic - Next topic

Shawn Anderson

I'm adding lines of text to a text box, and I want to move the cursor to the end of the text box.
This doesn't work:


Function updateList(t As String) As Long
Local oldText, newText As String 
Local endPos As Long

oldText=FF_TextBox_GetText (HWND_MAINFORM_LIST1) 

If oldText = "" Then 
    newText=t
Else
newText=oldText+$CrLf+t
End If

FF_TextBox_SetText (HWND_MAINFORM_LIST1, newText)

'move to the end of the list box       
endPos=FF_TextBox_GetSelEnd (HWND_MAINFORM_LIST1)
FF_TextBox_SetSel (HWND_MAINFORM_LIST1, endPos, endPos)

End Function


thanks


Rolf Brandt

Hello Shawn,

you are using textbox functions, but you are referencing a listbox (HWND_MAINFORM_LIST1).

Rolf

Shawn Anderson

Yes, sorry for the confusion.
I started with a list box, but changed it to a text box later.
I kept the name the same so I wouldn't have to change references to it in my code.
I guess I could do a global search/replace but I didn't think of that at the time.
HWND_MAINFORM_LIST1 is actually a text box.

TechSupport

Hi Shawn,

The problem is that when you SetText into the edit control, the selection points are reset to zero.

Therefore, instead of using this line:
   endPos=FF_TextBox_GetSelEnd (HWND_MAINFORM_LIST1)

Use this line instead:
   endpos = GetWindowTextLength(HWND_MAINFORM_LIST1)


Hope this works for you. I did a test using your code and it seemed to worked pretty well.

Shawn Anderson

Thanks.

GetWindowTextLength does give me the correct number of characters, but it in a multiline text box, it doesn't scroll down to the last line.
I tried using %EM_SCROLLCARET but still no luck.


Local i As Long

mainDlg=hWndForm

For i = 1 To 20

updateList("test"+Str$(i))
Next



Function updateList(t As String) As Long
Local oldText, newText As String 
Local endPos As Long

oldText=FF_TextBox_GetText (HWND_MAINFORM_LIST1) 

If oldText = "" Then 
    newText=t
Else
newText=oldText+$CrLf+t
End If

FF_TextBox_SetText (HWND_MAINFORM_LIST1, newText)

'move to the end of the list box       
endPos=GetWindowTextLength(HWND_MAINFORM_LIST1)     
FF_TextBox_SetSel (HWND_MAINFORM_LIST1, endPos-1, endPos-1)
Control Send mainDlg, HWND_MAINFORM_LIST1, %EM_SCROLLCARET, 0, 0   

End Function



Shawn Anderson

I took a little different route and got this to work.
This would not work well if you had lots and lots of text in your textbox, but this worked for me:


Function updateList(t As String) As Long
Local oldText, newText As String 
Local tLines As Long   
Local i As Long

oldText=FF_TextBox_GetText (HWND_MAINFORM_LIST1) 

If oldText = "" Then 
    newText=t
Else
newText=oldText+$CrLf+t
End If

FF_TextBox_SetText (HWND_MAINFORM_LIST1, newText)         

' move to the bottom
tLines=FF_TextBox_GetLineCount(HWND_MAINFORM_LIST1)
    For i =1 To tLines
      FF_TextBox_Scroll (HWND_MAINFORM_LIST1,%sb_LineDown)
    Next

End Function

TechSupport

Hi Shawn,

The following works... just make sure that you set the %ES_AUTOVSCROLL of the multiline textbox.


Function updateList(t As String) As Long
Local oldText, newText As String 
Local endPos As Long

oldText=FF_TextBox_GetText (HWND_MAINFORM_LIST1) 

If oldText = "" Then 
    newText=t
Else
newText=oldText+$CrLf+t
End If

FF_TextBox_SetText (HWND_MAINFORM_LIST1, newText)

'move to the end of the list box       
endpos = GetWindowTextLength(HWND_MAINFORM_LIST1)
FF_TextBox_SetSel (HWND_MAINFORM_LIST1, endPos, endPos)

    SendMessage HWND_MAINFORM_LIST1, %EM_SCROLLCARET, 0, 0 

SetFocus HWND_MAINFORM_LIST1

End Function


Shawn Anderson