Sorting ListViewGadgets

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

Hi,
I'm working on getting file names from a directory
with ExamineDirectory command and stuffing the
results into a ListViewGadget.

Everything works well, except the ListViewGadget
does not display the filenames in alphabetical order.

How can I sort the ListViewGadget? Or do I need
to stuff the results in an array first, then
insert the array into the LV?

The AddGadgetItem "position" flag doesn't work here.

Regards,
--blueb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

I think you must sort the array first. If you want to allow the user to sort the list afterwards, check this:

viewtopic.php?t=869

Bye,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

That's what I thought.

I'll take a look at your sample.

Thanks,
--blueb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

You simply create a ListBox with the styles:
#LBS_SORT | #LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS
and for adding new stuff you use:
SendMessage_(handle, #LB_ADDSTRING, 0, String).

Code: Select all

hWnd = OpenWindow(1,100,100,400,300,#PB_Window_SystemMenu,"ListBox Sort")
       CreateGadgetList(hWnd)
       ListViewGadget(1, 10,10,280,280,#LBS_SORT | #LBS_NOINTEGRALHEIGHT | #LBS_HASSTRINGS)
       StringGadget  (2,300,50, 90, 20, "Type here")
       ButtonGadget  (3,320,75, 50, 20, "Add")

Repeat
   Select WaitWindowEvent()
      Case #PB_EventCloseWindow: End
      Case #PB_EventGadget
           Select EventGadgetID()
              Case 1 ; ListView
                If EventType() = #PB_EventType_LeftDoubleClick
                   ; show the selected listview entry on doubleclick
                   MessageRequester("INFO",GetGadgetItemText(1,GetGadgetState(1),0),0)
                EndIf
              Case 3 ; Button: Add
                SendMessage_( GadgetID(1), #LB_ADDSTRING, 0, GetGadgetText(2))
           EndSelect
   EndSelect
ForEver
cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by blueb.

Thanks Danilo.

SendMessage did the trick! :)

Regards,
--blueb
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Danilo: Your tab indents are 3 spaces, not 2? Does the new editor
let us specify the value now?


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Hehe... PB :)

Look at the code - i use 2, 3 and 4 spaces. :)
Its my personal coding style:

Code: Select all

If x = 1   next line here, 3 spaces
Endif

Case 1
     Code here, 5 spaces
Case 2
     Code here
But now, Fred said i should always use 2 spaces
for indents... so all my personal style got
mixed up - but is still very readable, IMHO.

For me, mostly 3 spaces and TAB set to 8 or 10 is OK.

You´ll see the complete new Editor in few hours
with 3.40... :)

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
Originally posted by Danilo


You´ll see the complete new Editor in few hours
with 3.40... :)

cya,
...Danilo
Which time frame :)
Earth :)
Universe :)


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Andre.

I would say: look for the v3.40 update tommorow late night (12.00 pm) :)

Regards
André

*** German PureBasic Support ***
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.
Which time frame :)
Earth :)
Universe :)
Sorry Franco: I reported some bugs and correct some documentation
last night for Fred, so I may have contributed to delaying the
release. At least it'll be a more bug-free release! :)


PB - Registered PureBasic Coder
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

:)

Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
Post Reply