It is currently Sun May 19, 2013 4:44 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 2:38 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 61
Location: Melbourne, AUS
Hi,

I want to set an intial selection for a ListIconGadget (based on data read from a user's config file).

I can do this very simply for a ListViewGadget using SetGadgetText (which works really well).

Is there an equivalent function for a ListIconGadget ??

The Help file appears to imply there isn't !!

It only mentions ListViewGadget:

ListViewGadget(): selects the item that exactly matches the given text

Is there a way to do this for a ListIconGadget ??

Thanks,

Neil


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 3:06 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Mar 24, 2004 11:04 pm
Posts: 761
Location: Seattle, USA
Hi Neil,
SetGadgetState() will select an item for you in ListIconGadget. You just provide as arguments the gadget and item (line number) you want selected.

_________________
Win7 x64, PB x86


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 3:18 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 61
Location: Melbourne, AUS
Hi USCode,

Ahh that's the problem - I don't know the line number.

SetGadgetText will find the line number and make it the current selection.
Code:
SetGadgetText(#Gadget_Main_lServers, "find this value")


Neil


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 3:52 am 
Offline
User
User
User avatar

Joined: Sat Jul 23, 2011 1:13 am
Posts: 61
It's always best to store the gadged-data in variables, lists or arrays.
Working off the gadget with GetGadgetState() etc is not the best method.

Better work with an array and update the gadget accordingly.



Code:
Dim Array.s(4)
Array(0) = "Bla"
Array(1) = "Blubb"
Array(2) = "Bli Bla Bleh"
Array(3) = "Shoop di Whoop"

OpenWindow(0, 0, 0, 400, 300, "ListIcon", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ListIconGadget(0, 0, 0, 400, 300, "Data", 390,  #PB_ListIcon_FullRowSelect)
;ListViewGadget(0, 0, 0, 400, 300)

For a = 0 To 3
   AddGadgetItem(0, a, Array(a))
Next

For a = 0 To 3
   If Array(a) = "Bli Bla Bleh"
      SetGadgetState(0,a)
   EndIf
Next

Repeat    
Until WaitWindowEvent()=#PB_Event_CloseWindow


I don't know why but nothing is selected with a ListIconGadget. It works fine with the ListView.

SetGadgetItemState(0, a, #PB_ListIcon_Selected) doesn't seem to work either :?

_________________
PB 4.6b3 - Win7 32


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 4:43 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Mar 24, 2004 11:04 pm
Posts: 761
Location: Seattle, USA
Neil wrote:
Ahh that's the problem - I don't know the line number.

SetGadgetText will find the line number and make it the current selection.

Just loop through the list column you want to search and when you find the desired text (using GetGadgetItemText(), call SetGadgetState().

_________________
Win7 x64, PB x86


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 5:36 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 61
Location: Melbourne, AUS
ok - I worked out how to do this using:

Code:
CountGadgetItems(#Gadget_Main_lProjects)


and then looping through the values.

It would be a lot easier if there was a single function as per ListViewGadget !!

Anyway, my question now is:

How do I make the selection centred vertically in the List gadget on the form?

My list is a lot longer than the space on the form.

Thanks,

Neil


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 7:33 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
If your app is Windows only, take a look at Gnozal's PureLVSORT library, which does a lot more than sort.

http://gnozal.ucoz.com/

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 8:06 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 61
Location: Melbourne, AUS
Hey that's got it.

Code:
PureLVSORT_ScrollToRow(#Gadget_Main_lProjects, i)


Good old gnozal to the rescue again !!

Thanks,

Neil


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 8:30 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Windows only, no lib needed.

; Make sure the line (i) is visible

Code:
SendMessage_(GadgetID(#Gadget_Main_lProjects), #LVM_ENSUREVISIBLE, i, 0)

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 8:56 am 
Offline
Addict
Addict
User avatar

Joined: Thu Apr 21, 2005 2:38 pm
Posts: 813
Location: Germany
Fangbeast's API call doesn't necessarily center the chosen row. It only
takes care that this row is visible (in most cases as the second row
from the top or bottom). Those who need a cross-platform solution
may take a look into an example for Windows, Linux and MacOS X
which I already posted in the German forum. The Windows code uses
Fangbeast's API call but the Linux and MacOS API calls do indeed center
the row vertically:
http://www.purebasic.fr/german/viewtopi ... 80&start=6


Top
 Profile  
 
 Post subject: Re: How to set initial selection for ListIconGadget
PostPosted: Tue Mar 13, 2012 9:00 am 
Offline
PureBasic Protozoa
PureBasic Protozoa
User avatar

Joined: Fri Apr 25, 2003 3:08 pm
Posts: 3011
Shardik wrote:
Fangbeast's API call doesn't necessarily center the chosen row.


Whoopsies!

I know I saw something on the forum that could do this but stuffed if I can remember the post now. I'll look later tonight.

_________________
Resist FaceBorg or have your ass laminated!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 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