Page 1 of 1

Listview last item

Posted: Fri Feb 05, 2021 4:05 pm
by bfernhout
When i make a listview, this work perfect
Then the items to add i use

Code: Select all

AddGadgetItem(#ListView,-1,Text)
This is also good.
But when i add more then the listview can show the last added text is not showing. The side is showing a shift bar to indicate that there was added a item.
Normaly that is no problem. But i like to see the last added item at the bottom of the listview.

Is there a way to get this done.

Example code:

Code: Select all

Enumeration FormWindow
  #Window_1
EndEnumeration

Enumeration FormGadget
  #ListView_0
  #Button_0
  #Button_1
EndEnumeration

Global number.i
Procedure OpenWindow_1(x = 0, y = 0, width = 205, height = 250)
  OpenWindow(#Window_1, x, y, width, height, "", #PB_Window_ScreenCentered)
  ListViewGadget(#ListView_0, 5, 35, 195, 165)
  ButtonGadget(#Button_0, 5, 210, 90, 30, "Add Item")
  ButtonGadget(#Button_1, 110, 210, 90, 30, "Quit")
EndProcedure

Procedure Window_1_Events(event)
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0  ; Add item
          AddGadgetItem(#ListView_0,-1,"Added Item"+ Str(Number))
          Number+1
        Case #Button_1  ; End
          End
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

Openwindow_1()
Repeat
  Window_1_events(WaitWindowEvent(20))
ForEver
When adding the items until number 10 (which is the last item that is showing) the next number is not showing.

Re: Listview last item

Posted: Fri Feb 05, 2021 4:27 pm
by Gérard

Code: Select all

Procedure Window_1_Events(event)
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0  ; Add item
          AddGadgetItem(#ListView_0,-1,"Added Item"+ Str(Number))
          SetGadgetState(#ListView_0, Number) ; <---- add this
          Number+1
        Case #Button_1  ; End
          End
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

Re: Listview last item

Posted: Sat Feb 06, 2021 4:27 pm
by bfernhout
Thanks for the info. Why is this not documented. There are some exampels but not very expanded.

For the use of the code i had changed some small things. Because the number that was here provided is not in the original program.
There are added lines of executed commands but i found a easy solution that is working very well.

Code: Select all

Procedure Window_1_Events(event)
  Select event
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button_0  ; Add item
          AddGadgetItem(#ListView_0,-1,"Added Item"+ Str(Number))
          SetGadgetState(#ListView_0, CountGadgetItems(#ListView)-1) ; <---- changed this
          Number+1
        Case #Button_1  ; End
          End
      EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure
The count give the exact total of items in the listview. But the pointer to the last item is with the index one less.
This is working for me. See the changed line. That was your solution at first.

Very much thanks for the solution anyway.

I am reproducing a VB5 code and using PB form designer. The code is now ready. When the rest of the program is finished i will try to write a book about it. So there is some more understanding of the windows environment.

Re: Listview last item

Posted: Sat Feb 06, 2021 5:56 pm
by VB6_to_PBx
bfernhout ,
i fixed and added to your Code above :

Code: Select all

SetGadgetState(#ListView_0, CountGadgetItems(#ListView_0)-1) ;<<---- changed this  .... i fixed Error=#ListView  to #ListView_0

Code: Select all

SetActiveGadget(#ListView_0) ;<<--- this lets you immediately be able to use [Home] or [End] KeyBoard Keys after you add ListViewGadget Item
can immediately use [Page Up] , [Page Down] , etc Keyboard Keys

Code: Select all

Enumeration FormWindow
  #Window_1
EndEnumeration

Enumeration FormGadget
  #ListView_0
  #Button_0
  #Button_1
EndEnumeration

Global number.i
Procedure OpenWindow_1(x = 0, y = 0, width = 205, height = 250)
  OpenWindow(#Window_1, x, y, width, height, "", #PB_Window_ScreenCentered)
  ListViewGadget(#ListView_0, 5, 35, 195, 165)
  ButtonGadget(#Button_0, 5, 210, 90, 30, "Add Item")
  ButtonGadget(#Button_1, 110, 210, 90, 30, "Quit")
EndProcedure

Procedure Window_1_Events(event)
  Select event
  Case #PB_Event_Gadget
       Select EventGadget()
       Case #Button_0  ; Add item
            AddGadgetItem(#ListView_0,-1,"Added Item"+ Str(Number))
            ;SetGadgetState(#ListView_0, Number) ; <---- add this
            SetGadgetState(#ListView_0, CountGadgetItems(#ListView_0)-1) ;<<---- changed this  .... i fixed Error=#ListView  to #ListView_0
            Number + 1
            SetActiveGadget(#ListView_0) ;<<--- this lets you immediately be able to use [Home] or [End] KeyBoard Keys after you add ListViewGadget Item
       Case #Button_1  ; End
            End
       EndSelect
  EndSelect
  ProcedureReturn #True
EndProcedure

Openwindow_1()
Repeat
  Window_1_events(WaitWindowEvent(20))
ForEver


Re: Listview last item

Posted: Fri Feb 12, 2021 12:41 pm
by bfernhout
Thanks. Cause of the difference between to example code and my original code. the namegiving was wrong.

Its nice to see that someone is taking intrest in this. The page up and page down is a beautifull option. Altrough i do not need it here. I need to add command lines atr the bottom and got that is view. This is working so i am happy. Thank you for the help.

bart.