Sign in to follow this  
Followers 0
Dana

Scrolling in

5 posts in this topic

I'm working with a GUI with GUICtrlCreateListView, GUICtrlCreateListViewItem, and GUICtrlSetData to display COM port data as it's received. That's working fine, but when the number of lines in the list exceeds the height of the ListView box, and I get a scroll bar. That would also be OK, but the new data received goes to the bottom of the list where it's not visible. Is there any way to force the list to scroll to the current line, or to a specified line?

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Thanks... that almost does it. Seems like it should, but it only works when I rewrite to an existing line, and I don't see why. Here I have some code that reads from a com port and puts the result in one of two colums depending on the string. If both columns are written to, it fills in another column.

$w = 600
$h = 800
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode 
$datawindow = GUICreate("Data Collection", $w, $h)
GUICtrlCreateLabel("Part Number: " & $partnum & "   Job Number: " & $job, 30, 10)
GUICtrlCreateLabel(" Plunger Depth Gage (A): " & $gageA & " Ball Depth Gage ( B) : " & $gageB & "   Clearance: " & $clearance, 30, 30)
$okbutton = GUICtrlCreateButton("OK", 30, $h-40, 60)
$cancelbutton = GUICtrlCreateButton("Cancel", $w-30-60, $h-40, 60)
$datalist = GUICtrlCreateListView("No.|Plunger Depth|Ball Depth|  |Shaft Length",30, 50, 540, $h- 100)
Dim $balldepth[256]
Dim $plungerdepth[256]
Dim $shaftlength[256]
Dim $line[256]
GUISetOnEvent($GUI_EVENT_CLOSE, "CancelClicked")
GUICtrlSetOnEvent($cancelbutton, "CancelClicked")
GUICtrlSetOnEvent($okbutton, "OKClicked")
GUISetState(@SW_SHOW)
$anum = 0
$bnum = 0
$dataline = 0
While 1
    $instring = StringStripWS(_CommGetLine(@CR,0,300),8)
;Gageport string is number, reading (-.12345), , gage # (01 or 02)
    $readnum = StringLeft($instring, StringInStr($instring, ",")-1); read number from gage; not using this
    $instring = StringTrimLeft($instring, StringInStr($instring, ","))
    $value = StringLeft($instring, StringInStr($instring, ",")-1)
    $instring = StringTrimLeft($instring, StringInStr($instring, ","))
    $gageno = StringTrimLeft($instring, StringInStr($instring, ",")); second trim due to blank value field
;debug box
;$return = MsgBox(4097, "data received", "Reading: " & $readnum & @CRLF & "Value: " & $value & @CRLF & "Gage: " & $gageno)
;If ($return == 2) Then Exit
    
    If ($gageno == "01") Then
    ;MsgBox(4096, "debug", "got here")
        $anum = $anum + 1
        $plungerdepth[$anum] = $value
        If ($anum > $bnum) Then
            $line[$anum] = GUICtrlCreateListViewItem("-|-|-|-|-", $datalist); create a new line
            $balldepth[$anum] = "-"
        EndIf
        $dataline = $anum
    ElseIf ($gageno == "02") Then
        $bnum = $bnum + 1
        $balldepth[$bnum] = $value
        If ($bnum > $anum) Then
            $line[$bnum] = GUICtrlCreateListViewItem("-|-|-|-|-", $datalist); create a new line
            $plungerdepth[$bnum] = "-"
        EndIf
        $dataline = $bnum
    Else
    ;MsgBox(4096, "debug", "line " & $dataline & " A: " & $anum & " B: " & $bnum)   
    EndIf
    If ($plungerdepth[$dataline] <> "-" And $balldepth[$dataline] <> "-") Then $shaftlength[$dataline] = $plungerdepth[$dataline] + $balldepth[$dataline] + $clearance 
    $itemtext = $dataline & "|" & $plungerdepth[$dataline]  & "|" & $balldepth[$dataline] & "| |" & $shaftlength[$dataline]
;MsgBox(4096, "debug", "line " & $dataline & " A: " & $anum & " B: " & $bnum & @CRLF & $itemtext)
    GUICtrlSetData($line[$dataline], $itemtext)
    _GUICtrlListView_EnsureVisible($datalist, $dataline)
WEnd

The problem is that _GUICtrlListView_EnsureVisible($datalist, $dataline) only moves the list when the second value is written to the list; the first value written still disappears below the bottom of the list.

Edited by Dana

Share this post


Link to post
Share on other sites

GUICtrlSetData($line[$dataline], $itemtext)    
$count = _GUICtrlListView_GetItemCount($datalist)
_GUICtrlListView_EnsureVisible($datalist, $count)oÝ÷ Ûú®¢×ºÝ7éÊ.Ü"VÞ¶¬jg¯j[jÍ7éÖ­jX§{^ý§]xì%w§ ÈßÙ¢§]xì%w­éÈÂ¥v}ýµ·®²)àÓ~¢éí#e§¶+m¢Ç+¢Y[iÉ.¦Ú0êÞ¶§{Úç¬ÆÞxu×(¶+ZºÚ"µÍWÑÕRPÝÝY]×Ñ[ÝUÚXJ  ÌÍÙ][Ý  ÌÍÙ][[KLJ

solves all the problems.

Thanks for the assistance!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0