How to Scroll (Editor_Input = EditorGadget) to Line x ?

Just starting out? Need help? Post your questions and find answers here.
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by vmars316 »

Thanks in advance :
How to Scroll (Editor_Input = EditorGadget) to Line x ?
The following code Runs fine , Except it doesn't Scroll Editor_Input .

Code: Select all

        Case Editor_Output 
;Global Editor_Input , Editor_Output , HelpButton , 
;       itemText$ , selectedItem , event = 0 , spacePosition , number$ ,
;       Editor_Input_LineNumber = 0 

    If EventGadget() = Editor_Output And EventType() = #PB_EventType_LeftClick  ; Check for left click on the ListView
        ; Get the selected item index
        selectedItem = GetGadgetState(Editor_Output) ; Assuming Editor_Output is the ID of the ListView
        If selectedItem <> -1
            ; Fetch the text of the selected item 
            itemText$ = GetGadgetItemText(Editor_Output, selectedItem)
            ; Find the position of the first space
            spacePosition = FindString(itemText$, " ", 0)
            If spacePosition <> 0
                ; Extract the number before the first space
                number$ = Left(itemText$, spacePosition - 1)
                ; Convert string number to integer
                Editor_Input_LineNumber = Val(number$) - 1  ; Convert to zero-based index if needed
                ; Scroll to the line in the Editor_Input gadget
                SetGadgetState(Editor_Input, Editor_Input_LineNumber)
                MessageRequester("Event Detected", "Left click on ListView detected on item #" + Str(selectedItem) + " - Number: " + number$ + " (" + itemText$ + ")")
            EndIf
        EndIf
    EndIf   
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by netmaestro »

For windows:

Code: Select all

OpenWindow(0,0,0,640,480,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
EditorGadget(0,0,0,640,480)
For a = 0 To 100
  AddGadgetItem(0, a, "Line "+Str(a))
Next
SendMessage_(GadgetID(0), #EM_LINESCROLL, 0, 31)
SetGadgetState(0,31)
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
BERESHEIT
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by vmars316 »

netmaestro , Wonderfu!!
Thanks
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by vmars316 »

This code creates item lines 0 thru 5
and then creates item lines 0 thru 5 Again .

Code: Select all

; Author: Danilo (updated for PB4.00 by blbltheworm)
; Help from netmaestro 
OpenWindow(0,200,200,300,500,"Test",#PB_Window_SystemMenu) 
  ButtonGadget(125,5,5,100,29,"Click Me !") 
  EditorGadget(2,5,50,290,450) 

  Procedure ClickMe()
;    Global  
    For i = 0 To 2 
      AddGadgetItem(2,-1,"Item "+  Str(i) ) ; RSet(Str(i),4,"0")) 
      SendMessage_(GadgetID(2),#EM_LINESCROLL,1,1) 
     Delay(100) 
    Next i 
EndProcedure ; ClickMe()
    
  Repeat 
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow : End 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 125 ; Button 1 
;            SetGadgetState(106,MyImage(2,40,20,Random($FFFFFF))) 
            ClickMe()
        EndSelect 
    EndSelect 
  ForEver 

How can it be modified to create item lines 0 thru 5
and then creates item lines 6 thru 10 Again ?

Thanks
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
TassyJim
Enthusiast
Enthusiast
Posts: 183
Joined: Sun Jun 16, 2013 6:27 am
Location: Tasmania (Australia)

Re: How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by TassyJim »

vmars316 wrote: Sun Apr 14, 2024 1:55 am This code creates item lines 0 thru 5
and then creates item lines 0 thru 5 Again .
...
How can it be modified to create item lines 0 thru 5
and then creates item lines 6 thru 10 Again ?

Thanks

Code: Select all

; Author: Danilo (updated for PB4.00 by blbltheworm)
; Help from netmaestro 
OpenWindow(0,200,200,300,500,"Test",#PB_Window_SystemMenu) 
  ButtonGadget(125,5,5,100,29,"Click Me !") 
  EditorGadget(2,5,50,290,450) 

  Procedure ClickMe()
    ;    Global  
    linecount = CountGadgetItems(2)
    For i = 0 To 2 
      AddGadgetItem(2,-1,"Item "+  Str(i+linecount) ) ; RSet(Str(i),4,"0")) 
      SendMessage_(GadgetID(2),#EM_LINESCROLL,1,1) 
     Delay(100) 
    Next i 
EndProcedure ; ClickMe()
    
  Repeat 
    Select WaitWindowEvent() 
      Case #PB_Event_CloseWindow : End 
      Case #PB_Event_Gadget 
        Select EventGadget() 
          Case 125 ; Button 1 
;            SetGadgetState(106,MyImage(2,40,20,Random($FFFFFF))) 
            ClickMe()
        EndSelect 
    EndSelect 
  ForEver 

vmars316
Enthusiast
Enthusiast
Posts: 474
Joined: Fri Jun 29, 2012 12:24 am
Contact:

Re: How to Scroll (Editor_Input = EditorGadget) to Line x ?

Post by vmars316 »

Thanks TassyJim , Perfect .
vmars.us Win11 x64 , Martin Guitar 000-16 (1995)
"All things in moderation , except for love and forgiveness."
Post Reply