Problem to list files in a listview

Discuss GUI programming with the RapaGUI plugin here
Post Reply
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Problem to list files in a listview

Post by papiosaur »

Hello,

i have a problem with this code to list files in a listview:

Code: Select all

OpenDirectory(1, Dir$)
e = NextDirectoryEntry(1)
While e <> Nil
	If e.type = #DOSTYPE_FILE
	   moai.DoMethod("lv1", "Insert", "Top", e.name)
	EndIf
	e = NextDirectoryEntry(1)
Wend
CloseDirectory(1)
All files are named like that: UserXXX.cgl

Files are listed like that:

User030.cgl
User002.cgl
User003.cgl
User004.cgl
User005.cgl
User006.cgl
User007.cgl
User008.cgl
User009.cgl
...

At the normal place of User030.cgl, i have
User001.cgl
User060.cgl
User032.cgl
...

At the normal place of User060.cgl, i have
User031.cgl
User090.cgl
User062.cgl

Any ideas please?
Thanks for your help
plouf
Posts: 666
Joined: Sun Feb 04, 2018 11:51 pm
Location: Athens,Greece

Re: Problem to list files in a listview

Post by plouf »

the problem is that you dont have sorted by name?
dos names is NOT guaranteed to be sorted alphabetically.

hollywood has sorting function you must call for list view which is what you must use if thats the case, and your column MUST have sortable="true"
here is an example with sorting
@REQUIRE "RapaGUI"

Function p_CmpFunc(e1, e2)
Local v1, v2 = Val(e1), Val(e2)
If v1 < v2 Then Return(-1)
If v1 > v2 Then Return(1)
Return(0)
EndFunction

moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application>
<window title="Test program">
<vgroup>
<listview id="lv" notify="compareitems" forcemode="dataview">
<column title="sort me" sortable="true"/>
</listview>
</vgroup>
</window>
</application>
]])

t = {1289255, 1393876, 1611837, 172877653, 1872262, 1886087, 236550,
2690523, 355653720, 36295634, 4617075, 4848326, 5497692,
61047095, 6256502}

InstallEventHandler({RapaGUI = Function(msg)
If msg.attribute = "CompareItems" Then Return(p_CmpFunc(msg.entry1, msg.entry2))
EndFunction})

For Local k = 0 To ListItems(t) - 1 Do moai.DoMethod("lv", "insert", 0, t[k])

Repeat
WaitEvent
Forever
Christos
papiosaur
Posts: 217
Joined: Fri Mar 31, 2023 1:34 pm

Re: Problem to list files in a listview

Post by papiosaur »

Thanks a lot plouf!

It work with sortable="true" option

Thanks for the example for function to sort a column too :-)
Post Reply