Listview last item

You need some new stunning features ? Tell us here.
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Listview last item

Post 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.
From my first self made computer till now I stil like computers.
Gérard
User
User
Posts: 43
Joined: Sat Oct 17, 2015 6:00 pm
Location: France
Contact:

Re: Listview last item

Post 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
■ Win10 64-bit (Intel Celeron CPU N2920 @ 1.86GHz, 4,0GB RAM, Intel HD Graphics) & PB 6.00 LTS
■ Vivre et laisser vivre.
■ PureBasic pour le fun
■ cage sur le forum Français
■ Mes sites: http://pbcage.free.fr - http://yh.toolbox.free.fr
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Listview last item

Post 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.
From my first self made computer till now I stil like computers.
User avatar
VB6_to_PBx
Enthusiast
Enthusiast
Posts: 617
Joined: Mon May 09, 2011 9:36 am

Re: Listview last item

Post 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

 
PureBasic .... making tiny electrons do what you want !

"With every mistake we must surely be learning" - George Harrison
User avatar
bfernhout
Enthusiast
Enthusiast
Posts: 123
Joined: Mon Feb 26, 2018 10:41 pm
Location: Netherlands
Contact:

Re: Listview last item

Post 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.
From my first self made computer till now I stil like computers.
Post Reply