Page 1 of 2

ListIconGadget sort on column

Posted: Mon Jan 29, 2007 8:31 am
by utopiomania
This code sorts listicongadget columns. It handles strings, but the compare procedure
rsets() them before comparing, so (integer) numbers will be sorted correctly too.

It also moves the item state with the items, such as checkbox status and if the item is
currently selected or not.

Code: Select all

;sort order,0 ascending/listicongadget cols
global order, li = 1 ;listicon id
global cols = 4, max = 6

procedure swapItems(id, item1, item2, cols)
  for col = 0 to cols - 1
    ;swap item text
    text.s = getGadgetItemText(id, item1, col)
    setGadgetItemText(id, item1, getGadgetItemText(id, item2, col), col)
    setGadgetItemText(id, item2, text, col)

    ;swap item data
    dta = getGadgetItemData(id, item1)
    setGadgetItemData(id, item1, getGadgetItemData(id, item2))
    setGadgetItemData(id, item2, dta)
    
    ;swap item fg colors
    fg = getGadgetItemColor(id, item1, #PB_GADGET_FRONTCOLOR, col)
    setGadgetItemColor(id, item1, #PB_GADGET_FRONTCOLOR, getGadgetItemColor(id, item2, #PB_GADGET_FRONTCOLOR, col), col)
    setGadgetItemColor(id, item2, #PB_GADGET_FRONTCOLOR, fg, col)

    ;swap item bg colors
    bg = getGadgetItemColor(id, item1, #PB_GADGET_BACKCOLOR, col)
    setGadgetItemColor(id, item1, #PB_GADGET_BACKCOLOR, getGadgetItemColor(id, item2, #PB_GADGET_BACKCOLOR, col), col)  
    setGadgetItemColor(id, item2, #PB_GADGET_BACKCOLOR, bg, col)
  next col
  ;swap checkbox/selected item states
  state = getGadgetItemState(id, item1)
  setGadgetItemState(id, item1, getGadgetItemState(id, item2))
  setGadgetItemState(id, item2, state)
endProcedure

procedure compare(s1.s, s2.s)
  ;rsets to compare numbers correctly
  sc1.s = ucase(rset(s1, max))
  sc2.s = ucase(rset(s2, max))
  if sc1 < sc2
    procedureReturn -1
  elseIf sc1 > sc2
    procedureReturn 1
  endIf
  procedureReturn 0
endProcedure

procedure qSortItems(id, order, col, cols, left, right)
  ;quicksort kernel, herbert schildt
  ;comparisons: n * log10(n), swaps: n/6 * log10(n)
  lft = left: rgt = right
  txt.s = getGadgetItemText(id, (lft + rgt) / 2, col)
  while lft <=rgt
    if order
      ;is descending
      while compare(getGadgetItemText(id, lft, col), txt) > 0 and lft < right
        lft + 1
      wend
      while compare(getGadgetItemText(id, rgt, col), txt) < 0 and lft < right
        rgt - 1
      wend
    else
      while compare(getGadgetItemText(id, lft, col), txt) < 0 and lft < right
        lft + 1
      wend
      while compare(getGadgetItemText(id, rgt, col), txt) > 0 and lft < right
        rgt - 1
      wend
    endIf
    if lft <= rgt
      swapItems(id, lft, rgt, cols)
      lft + 1: rgt - 1
    endIf
  wend
  if left < rgt
    qSortItems(id, order, col, cols, left, rgt)
  endIf
  if lft < right
    qSortItems(id, order, col, cols, lft, right)
  endIf
endProcedure

procedure quickSortItems(id, order, col, cols)
  ;quicksort wrapper
  qSortItems(id, order, col, cols, 0, countGadgetItems(id) - 1)
  procedureReturn order ! 1
endProcedure

procedure windowCallback(win, msg, wParam, lParam)
  ;code handles column header clicks and initiates sorts
  if msg = #WM_NOTIFY 
    *phdr.HD_NOTIFY = lParam
    if *phdr\hdr\code = #HDN_ITEMCLICK
      order = quickSortItems(li, order, *phdr\iItem, cols)
    endIf
  endIf    
  procedureReturn #PB_PROCESSPUREBASICEVENTS
endProcedure


;-driver
openWindow(0, 0, 0, 620, 500, "Adding items..", 13107201) 
setWindowCallback(@windowCallback())

;create the listicongadget
li = 1
listIconGadget(li, 0, 0, 620, 500, "Column 0", 150, 1073807369) 
addGadgetColumn(li, 1, "Column 1", 150) 
addGadgetColumn(li, 2, "Column 2", 150) 
addGadgetColumn(li, 3, "Column 3", 150)

;fill it with random data
for item = 0 to 999
  i.s = ""
  for n = 0 to max
    i + chr('A' + random(25))
  next n
  i + #LF$  
  for n = 0 to max
    i + chr('A' + random(25))
  next n
  i + #LF$  
  for n = 0 to max
    i + chr('A' + random(25))
  next n
  i + #LF$  
  for n = 0 to max
    i.s + chr('A' + random(25))
  next n
  addGadgetItem(li, -1, i)

  ;random item colors
  col = random(cols - 1)
  bgc = rgb(random(192) + 48, random(192) + 48, random(192) + 48)  
  setGadgetItemColor(li, item, #PB_GADGET_FRONTCOLOR, #WHITE, col)
  setGadgetItemColor(li, item, #PB_GADGET_BACKCOLOR, bgc, col)  

  windowEvent()
next item

;initial sort, ascending on col 0
setWindowTitle(0, "Sorting...")
order = 0
order = quickSortItems(li, order, 0, cols)

i = str(item) + " items, click header to sort in ascending/descending order"
setWindowTitle(0, i)

;loop while the callback handles sorting
repeat
until waitWindowEvent() = #PB_EVENT_CLOSEWINDOW
end
20091115, updated a bit

Posted: Sat Apr 21, 2007 4:05 pm
by Joakim Christiansen
Very very nice, thank you! :)

Posted: Fri Apr 27, 2007 9:16 pm
by utopiomania
You're welcome, and thanks for testing! :)

Posted: Sat Apr 28, 2007 12:37 pm
by Max
Hi utopiomania,
See also
http://www.purebasic.fr/english/viewtopic.php?t=26175

(tested and widely used)

Posted: Tue Sep 01, 2009 9:55 am
by Michael Vogel
Really a useful code, I'd try to do some (simple) changes...
• get rid of fixed values (4 columns etc.)
• start with same ordering when clicking on a new column
• use a symbol to indicate sort order

Here are the modifications...

Code: Select all

Procedure SortItemsNow(id,col)

	Protected Title.s=GetGadgetItemText(id,-1,col)
	Protected i,Order
	Protected Columns=SendMessage_(SendMessage_(GadgetID(id),#LVM_GETHEADER,0,0),#HDM_GETITEMCOUNT,0,0)
	
	#OrderSymbolSpace="  ";	"__"
	#OrderSymbolLen=4;		"__/\"

	i=Columns
	While i
		i-1
		Title=GetGadgetItemText(id,-1,i)
		Order=FindString(Right(Title,2),"/",1)
		If Order
			Title=Left(Title,Len(Title)-#OrderSymbolLen)
		EndIf
		If col=i
			Order=(Order+2)&1
			qSortItems(id,Order,col,Columns,0,CountGadgetItems(id)-1)
			Title=Title+#OrderSymbolSpace+Mid("/\/",Order+1,2)
		EndIf
		SetGadgetItemText(id,-1,Title,i)
	Wend

	ProcedureReturn #True

EndProcedure
Procedure windowCallback(win,msg,wParam,lParam)

	Protected *phdr.HD_NOTIFY

	If msg=#WM_NOTIFY
		*phdr.HD_NOTIFY=lParam
		If *phdr\hdr\code=#HDN_ITEMCLICK
			;Debug GadgetID(1)
			;Debug *phdr\hdr\hwndfrom
			;Debug *phdr\hdr\idfrom
			SortItemsNow(1,*phdr\iItem)
		EndIf
	EndIf

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure
The only thing I was not able to eliminate is the (fixed) Gadget ID - I would like to get this info from the callback message but failed :cry:

Michael

Posted: Tue Sep 01, 2009 10:50 am
by gnozal
Michael Vogel wrote:The only thing I was not able to eliminate is the (fixed) Gadget ID - I would like to get this info from the callback message but failed :cry:
You mean something like this ?

Code: Select all

SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom), *phdr\iItem) 

Posted: Tue Sep 01, 2009 11:36 am
by Michael Vogel
gnozal wrote:
Michael Vogel wrote:The only thing I was not able to eliminate is the (fixed) Gadget ID - I would like to get this info from the callback message but failed :cry:
You mean something like this ?

Code: Select all

SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom), *phdr\iItem) 
Hm,
maybe I'm to tired now for doing even easy things, but I'll get an error here :shock:

Code: Select all

EnableExplicit
;sort order,0 ascending/listicongadget cols
;Global cols=4
	
Procedure SortSwapItems(id,item1,item2,cols)
	Protected c
	Protected t.s

	For c=0 To cols-1
		t=GetGadgetItemText(id,item1,c)
		SetGadgetItemText(id,item1,GetGadgetItemText(id,item2,c),c)
		SetGadgetItemText(id,item2,t,c)
	Next c

	c=GetGadgetItemState(id,item1)
	SetGadgetItemState(id,item1,GetGadgetItemState(id,item2))
	SetGadgetItemState(id,item2,c)

EndProcedure
Procedure SortCompare(s1.s,s2.s)

	Protected t1.s=RSet(s1,24)
	Protected t2.s=RSet(s2,24)

	If UCase(t1)<UCase(t2)
		ProcedureReturn -1
	ElseIf UCase(t1)>UCase(t2)
		ProcedureReturn 1
	EndIf

	ProcedureReturn 0

EndProcedure
Procedure SortItems(id,order,col,cols,left,right)

	Protected l=left
	Protected r=right

	Protected t.s=GetGadgetItemText(id,(l+r)/2,col)

	While l<=r
		If order
			While SortCompare(GetGadgetItemText(id,l,col),t)>0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)<0 And l<right
				r-1
			Wend
		Else
			While SortCompare(GetGadgetItemText(id,l,col),t)<0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)>0 And l<right
				r-1
			Wend
		EndIf
		If l<=r
			SortSwapItems(id,l,r,cols)
			l+1
			r-1
		EndIf
	Wend

	If left<r
		SortItems(id,order,col,cols,left,r)
	EndIf

	If l<right
		SortItems(id,order,col,cols,l,right)
	EndIf

EndProcedure
Procedure SortItemsNow(id,col)

	Protected Title.s=GetGadgetItemText(id,-1,col)
	Protected i,Order
	Protected Columns=SendMessage_(SendMessage_(GadgetID(id),#LVM_GETHEADER,0,0),#HDM_GETITEMCOUNT,0,0)
	
	#OrderSymbolSpace="  ";	"__"
	#OrderSymbolLen=4;		"__/"

	i=Columns
	While i
		i-1
		Title=GetGadgetItemText(id,-1,i)
		Order=FindString(Right(Title,2),"/",1)
		If Order
			Title=Left(Title,Len(Title)-#OrderSymbolLen)
		EndIf
		If col=i
			Order=(Order+2)&1
			SortItems(id,Order,col,Columns,0,CountGadgetItems(id)-1)
			Title=Title+#OrderSymbolSpace+Mid("/\/",Order+1,2)
		EndIf
		SetGadgetItemText(id,-1,Title,i)
	Wend

	ProcedureReturn #True

EndProcedure
Procedure windowCallback(win,msg,wParam,lParam)

	Protected *phdr.HD_NOTIFY

	If msg=#WM_NOTIFY
		*phdr.HD_NOTIFY=lParam
		If *phdr\hdr\code=#HDN_ITEMCLICK
			Debug GadgetID(1)
			Debug *phdr\hdr\hwndfrom
			Debug *phdr\hdr\idfrom
			SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom),*phdr\iItem)
			;SortItemsNow(1,*phdr\iItem)
		EndIf
	EndIf

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure


;-driver
OpenWindow(0,0,0,620,500,"Adding items..",13107201)
SetWindowCallback(@windowCallback())

;create the listicongadget

ListIconGadget(1,0,0,620,500,"Column 0",150,1073807369)
AddGadgetColumn(1,1,"Column 1",150)
AddGadgetColumn(1,2,"Column 2",150)
AddGadgetColumn(1,3,"Column 3",150)

Global item.l
Global i.s
Global n

;fill it with random data
For item=0 To 99
	i.s=""
	i + Str(Random(2))+":"+RSet(Str(Random(59)),2,"0")+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(59))+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(20))+","+RSet(Str(Random(59)),2,"0")+"km"
	i + #LF$

	For n=0 To 9
		i.s + Chr('A' + Random(25))
	Next n

	AddGadgetItem(1,-1,i)
	WindowEvent()
Next item

i=Str(item) + " items,click header to sort in ascending/descending order"
SetWindowTitle(0,i)

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End

Posted: Tue Sep 01, 2009 12:27 pm
by gnozal
Sorry, I didn't read carefuly : the event / structure you are using are wrong imho.
The callback should be like this :

Code: Select all

Procedure windowCallback(win,msg,wParam,lParam) 
  
  Protected *phdr.NM_LISTVIEW
  
  If msg=#WM_NOTIFY 
    *phdr=lParam 
    If *phdr\hdr\code=#LVN_COLUMNCLICK
      SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom),*phdr\isubItem) 
    EndIf 
  EndIf 
  
  ProcedureReturn #PB_ProcessPureBasicEvents 
  
EndProcedure

Posted: Tue Sep 01, 2009 2:40 pm
by Michael Vogel
gnozal wrote:Sorry, I didn't read carefuly : the event / structure you are using are wrong imho.
[...]
Cool, thanks!
This whole windows-API-structures-pointers-constants-whatever-stuff is still a big riddle for me...

Michael

Re: ListIconGadget sort on column

Posted: Tue Jul 20, 2010 6:12 am
by Fangbeast
Michael, I hate to resurrect an old topic, but how do you sort on demand without changing the sort direction each time?

I tried "SortItemsNow(#MyGadget, 0)" and it changes the direction each time?

I'm even less adept at understanding API than most.

Re: ListIconGadget sort on column

Posted: Tue Jul 20, 2010 6:28 am
by Michael Vogel
Ua... not that old, but took me some minutes... :shock:

Here's the full code, so I don't have to do cut and pastes if you will have another question later on :lol:

Code: Select all

EnableExplicit
;sort order,0 ascending/listicongadget cols
;Global cols=4

Procedure SortSwapItems(id,item1,item2,cols)
	Protected c
	Protected t.s

	For c=0 To cols-1
		t=GetGadgetItemText(id,item1,c)
		SetGadgetItemText(id,item1,GetGadgetItemText(id,item2,c),c)
		SetGadgetItemText(id,item2,t,c)
	Next c

	c=GetGadgetItemState(id,item1)
	SetGadgetItemState(id,item1,GetGadgetItemState(id,item2))
	SetGadgetItemState(id,item2,c)

EndProcedure
Procedure SortCompare(s1.s,s2.s)

	Protected t1.s=RSet(s1,24)
	Protected t2.s=RSet(s2,24)

	If UCase(t1)<UCase(t2)
		ProcedureReturn -1
	ElseIf UCase(t1)>UCase(t2)
		ProcedureReturn 1
	EndIf

	ProcedureReturn 0

EndProcedure
Procedure SortItems(id,order,col,cols,left,right)

	Protected l=left
	Protected r=right

	Protected t.s=GetGadgetItemText(id,(l+r)/2,col)

	While l<=r
		If order
			While SortCompare(GetGadgetItemText(id,l,col),t)>0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)<0 And l<right
				r-1
			Wend
		Else
			While SortCompare(GetGadgetItemText(id,l,col),t)<0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)>0 And l<right
				r-1
			Wend
		EndIf
		If l<=r
			SortSwapItems(id,l,r,cols)
			l+1
			r-1
		EndIf
	Wend

	If left<r
		SortItems(id,order,col,cols,left,r)
	EndIf

	If l<right
		SortItems(id,order,col,cols,l,right)
	EndIf

EndProcedure
Procedure SortItemsNow(id,col)

	Protected Title.s=GetGadgetItemText(id,-1,col)
	Protected i,Order
	Protected Columns=SendMessage_(SendMessage_(GadgetID(id),#LVM_GETHEADER,0,0),#HDM_GETITEMCOUNT,0,0)

	#OrderSymbolSpace="  ";   "__"
	#OrderSymbolLen=4;      "__/"

	i=Columns
	While i
		i-1
		Title=GetGadgetItemText(id,-1,i)
		Order=FindString(Right(Title,2),"/",1)
		If Order
			Title=Left(Title,Len(Title)-#OrderSymbolLen)
		EndIf
		If col=i
			Order=(Order+2)&1
			SortItems(id,0*Order,col,Columns,0,CountGadgetItems(id)-1)
			Title=Title+#OrderSymbolSpace+Mid("/\/",0*Order+1,2)
		EndIf
		SetGadgetItemText(id,-1,Title,i)
	Wend

	ProcedureReturn #True

EndProcedure
Procedure windowCallback(win,msg,wParam,lParam)

	Protected *phdr.NM_LISTVIEW

	If msg=#WM_NOTIFY
		*phdr=lParam
		If *phdr\hdr\code=#LVN_COLUMNCLICK
			SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom),*phdr\isubItem)
		EndIf
	EndIf

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure


;-driver
OpenWindow(0,0,0,620,500,"Adding items..",13107201)
SetWindowCallback(@windowCallback())

;create the listicongadget

ListIconGadget(1,0,0,620,500,"Column 0",150,1073807369)
AddGadgetColumn(1,1,"Column 1",150)
AddGadgetColumn(1,2,"Column 2",150)
AddGadgetColumn(1,3,"Column 3",150)

Global item.l
Global i.s
Global n

;fill it with random data
For item=0 To 99
	i.s=""
	i + Str(Random(2))+":"+RSet(Str(Random(59)),2,"0")+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(59))+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(20))+","+RSet(Str(Random(59)),2,"0")+"km"
	i + #LF$

	For n=0 To 9
		i.s + Chr('A' + Random(25))
	Next n

	AddGadgetItem(1,-1,i)
	WindowEvent()
Next item

i=Str(item) + " items,click header to sort in ascending/descending order"
SetWindowTitle(0,i)

Repeat
Until WaitWindowEvent()=#PB_Event_CloseWindow
End



The changes are done in two lines, just search for "0*" which I have added now :mrgreen:

Cheers,
Michael

Re: ListIconGadget sort on column

Posted: Tue Jul 20, 2010 8:48 am
by Fangbeast
I don't know what I did wrong adding this, it's not sorting properly at all now. I wish to cut my head off, it's hurting.

I'm trying to get it to sort an entry into place as I add it but the sort is all over the place. AAARRRRGHGHGHGHGH

Re: ListIconGadget sort on column

Posted: Tue Jul 20, 2010 7:08 pm
by Michael Vogel
Fangbeast wrote:I don't know what I did wrong adding this, it's not sorting properly at all now. I wish to cut my head off, it's hurting.

I'm trying to get it to sort an entry into place as I add it but the sort is all over the place. AAARRRRGHGHGHGHGH
Give me a hint what I can try to do for you, do you modifying the code above or do you have something completely different (which could be posted)?

Here's what I believe you may want...

Code: Select all

EnableExplicit

Global SortedColumn=-1

Procedure SortSwapItems(id,item1,item2,cols)
	Protected c
	Protected t.s

	For c=0 To cols-1
		t=GetGadgetItemText(id,item1,c)
		SetGadgetItemText(id,item1,GetGadgetItemText(id,item2,c),c)
		SetGadgetItemText(id,item2,t,c)
	Next c

	c=GetGadgetItemState(id,item1)
	SetGadgetItemState(id,item1,GetGadgetItemState(id,item2))
	SetGadgetItemState(id,item2,c)

EndProcedure
Procedure SortCompare(s1.s,s2.s)

	Protected t1.s=RSet(s1,24)
	Protected t2.s=RSet(s2,24)

	If UCase(t1)<UCase(t2)
		ProcedureReturn -1
	ElseIf UCase(t1)>UCase(t2)
		ProcedureReturn 1
	EndIf

	ProcedureReturn 0

EndProcedure
Procedure SortItems(id,order,col,cols,left,right)

	Protected l=left
	Protected r=right

	Protected t.s=GetGadgetItemText(id,(l+r)/2,col)

	While l<=r
		If order
			While SortCompare(GetGadgetItemText(id,l,col),t)>0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)<0 And l<right
				r-1
			Wend
		Else
			While SortCompare(GetGadgetItemText(id,l,col),t)<0 And l<right
				l+1
			Wend
			While SortCompare(GetGadgetItemText(id,r,col),t)>0 And l<right
				r-1
			Wend
		EndIf
		If l<=r
			SortSwapItems(id,l,r,cols)
			l+1
			r-1
		EndIf
	Wend

	If left<r
		SortItems(id,order,col,cols,left,r)
	EndIf

	If l<right
		SortItems(id,order,col,cols,l,right)
	EndIf

EndProcedure
Procedure SortItemsNow(id,col)

	Protected Title.s=GetGadgetItemText(id,-1,col)
	Protected i,Order
	Protected Columns=SendMessage_(SendMessage_(GadgetID(id),#LVM_GETHEADER,0,0),#HDM_GETITEMCOUNT,0,0)

	#OrderSymbolSpace="  ";   "__"
	#OrderSymbolLen=4;      "__/"

	SortedColumn=col
	i=Columns
	While i
		i-1
		Title=GetGadgetItemText(id,-1,i)
		Order=FindString(Right(Title,2),"/",1)
		If Order
			Title=Left(Title,Len(Title)-#OrderSymbolLen)
		EndIf
		If col=i
			Order=(Order+2)&1
			SortItems(id,0*Order,col,Columns,0,CountGadgetItems(id)-1)
			Title=Title+#OrderSymbolSpace+Mid("/\/",0*Order+1,2)
		EndIf
		SetGadgetItemText(id,-1,Title,i)
	Wend

	ProcedureReturn #True

EndProcedure
Procedure windowCallback(win,msg,wParam,lParam)

	Protected *phdr.NM_LISTVIEW

	If msg=#WM_NOTIFY
		*phdr=lParam
		If *phdr\hdr\code=#LVN_COLUMNCLICK
			SortItemsNow(GetDlgCtrlID_(*phdr\hdr\hwndfrom),*phdr\isubItem)
		EndIf
	EndIf

	ProcedureReturn #PB_ProcessPureBasicEvents

EndProcedure

Procedure AddLine()

	Protected i.s=""
	Protected n

	i + Str(Random(2))+":"+RSet(Str(Random(59)),2,"0")+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(59))+"'"+RSet(Str(Random(59)),2,"0")+"''"
	i + #LF$

	i + Str(Random(20))+","+RSet(Str(Random(59)),2,"0")+"km"
	i + #LF$

	For n=0 To 9
		i.s + Chr('A' + Random(25))
	Next n

	AddGadgetItem(1,-1,i)
	WindowEvent()
EndProcedure

OpenWindow(0,0,0,620,500,"Adding items..",13107201)
SetWindowCallback(@windowCallback())

ListIconGadget(1,0,0,620,470,"Column 0",150,1073807369)
AddGadgetColumn(1,1,"Column 1",150)
AddGadgetColumn(1,2,"Column 2",150)
AddGadgetColumn(1,3,"Column 3",150)

ButtonGadget(999,10,474,200,22,"Add Item")

Global item.l
Global i.s
Global n

For item=0 To 10
	AddLine()
Next item

i=Str(item) + " items,click header to sort in ascending/descending order"
SetWindowTitle(0,i)

Repeat
	Select WaitWindowEvent()

	Case #PB_Event_Gadget
		AddLine()
		If SortedColumn>-1
			SortItemsNow(1,SortedColumn)
		EndIf

	Case #PB_Event_CloseWindow
		Break

	EndSelect

ForEver

Re: ListIconGadget sort on column

Posted: Wed Jul 21, 2010 12:38 pm
by Little John
Thanks, this is very useful !

Is there a way to display a little arrow or something in the respective column header, so that the user can see which column is currently sorted?

Regards, Little John

Re: ListIconGadget sort on column

Posted: Wed Jul 21, 2010 9:57 pm
by Andre
Anyone already adapted such an example code (for sorting by listicon header) to MacOS?