It is currently Fri Feb 26, 2021 7:05 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Listview last item
PostPosted: Fri Feb 05, 2021 4:05 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 96
Location: Netherlands
When i make a listview, this work perfect
Then the items to add i use
Code:
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview last item
PostPosted: Fri Feb 05, 2021 4:27 pm 
Offline
User
User

Joined: Sat Oct 17, 2015 6:00 pm
Posts: 17
Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview last item
PostPosted: Sat Feb 06, 2021 4:27 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 96
Location: Netherlands
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:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview last item
PostPosted: Sat Feb 06, 2021 5:56 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon May 09, 2011 9:36 am
Posts: 551
bfernhout ,
i fixed and added to your Code above :
Code:
SetGadgetState(#ListView_0, CountGadgetItems(#ListView_0)-1) ;<<---- changed this  .... i fixed Error=#ListView  to #ListView_0

Code:
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Listview last item
PostPosted: Fri Feb 12, 2021 12:41 pm 
Offline
User
User
User avatar

Joined: Mon Feb 26, 2018 10:41 pm
Posts: 96
Location: Netherlands
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye