Liberty BASIC Community Forum
« ListView Sort »

Welcome Guest. Please Login or Register.
Nov 23rd, 2017, 03:01am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: ListView Sort  (Read 90 times)
NSbrown
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx ListView Sort
« Thread started on: May 19th, 2017, 1:35pm »

Hello everyone,
Can anyone teach me how to perform sorting in ListView using api send massage?

Code:


    Struct LVCOLUMN, _
           mask As ulong, _
            fmt As long, _
             cx As long, _
       pszText$ As ptr, _
     cchTextMax As long, _
       iSubItem As long, _
         iImage As long, _
         iOrder As long

    Struct LVITEM, _
           mask As ulong, _
          iItem As long, _
       iSubItem As long, _
          state As ulong, _
      stateMask As ulong, _
       pszText$ As ptr, _
     cchTextMax As long, _
         iImage As long, _
         lParam As long, _
        iIndent As long


'listview constants
    LVS.NOSORTHEADER =   32768 : LVS.REPORT =             1 : LVS.SINGLESEL =          4 : LVS.SHOWSELALWAYS =      8
    LVS.SORTASCENDING =     16 : LVS.SORTDESCENDING =    32 : LVS.NOLABELWRAP =      128 : LVS.AUTOARRANGE =      256
    LVS.NOSCROLL =        8192 : LVS.ALIGNTOP =           0 : LVS.ALIGNLEFT =       2048 : LVS.NOCOLUMNHEADER = 16384
    LVIF.TEXT =              1 : LVIF.STATE =             8 : LVIS.UNSELECTED =        0 : LVIS.FOCUSED =           1
    LVIS.SELECTED =          2 : LVM.FIRST =           4096 : LVM.SETITEM =         4102 : LVM.INSERTITEM =      4103
    LVM.INSERTCOLUMN =    4123 : LVM.GETITEMCOUNT =    4100 : LVM.GETITEMA =        4101 : LVM.GETITEMTEXTA =    4141
    LVM.GETITEMSTATE =    4138 : LVM.SETITEMSTATE =    4139 : LVM.DELETEITEM =      4104 : LVM.DELETEALLITEMS =  4105
    LVM.SETTEXTCOLOR =    4132 : LVM.SETBKCOLOR=       4097 : LVM.SETTEXTBKCOLOR =  4134 : LVM.DELETEALLITEMS =  4105
    LVM.UPDATE =          4138 : LVIF.IMAGE         =     2 : LVCF.WIDTH =             2 : LVCF.TEXT =              4
    LVS.EX.GRIDLINES=        1 : LVCFMT.CENTER  =         2 : LVCFMT.RIGHT =           1 : LVCF.FMT =               1
    LVS.LIST=                3 : LVS.SMALLICON=           2 : LVSCW.AUTOSIZE=         -1

    LVS.EX.FULLROWSELECT = hexdec("20")
    LVM.SETEXTENDEDLISTVIEWSTYLE = LVM.FIRST + 54

    holdTxtColor=0
    holdBgColor=13825525


    nomainwin
    WindowWidth = 390
    WindowHeight = 232
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)

    open "untitled" for dialog as #1
    print #1, "font ms_sans_serif 10"
    print #1, "trapclose [quit.1]"


'Listview Report
    style =_WS_CHILD OR _WS_VISIBLE OR LVS.REPORT OR LVS.SHOWSELALWAYS OR LVS.EX.GRIDLINES
    hListview1 = CreateWindowEx(_WS_EX_CLIENTEDGE,"SysListView32","",style,0,  0, 380, 200,hwnd(#1),hInst)

'    call sendMessage  hListview1, _WM_SETFONT ,hFont ,1

     if colorOn=1 then
        call sendMessage hListview1,LVM.SETBKCOLOR,    0,holdBgColor
        call sendMessage hListview1,LVM.SETTEXTBKCOLOR,0,holdBgColor
        call sendMessage hListview1,LVM.SETTEXTCOLOR,  0,holdTxtColor
    end if

    if gridOn=0 then
       call sendMessage hListview1,LVM.SETEXTENDEDLISTVIEWSTYLE,LVS.EX.GRIDLINES,LVS.EX.GRIDLINES
     end if

'Set listview colum title, width, and format
    columnName$(1)="Nutrient"
    columnWidth(1)=200

    columnName$(2)="Unit"
    columnWidth(2)=75

    columnName$(3)="Amount"
    columnWidth(3)=100


    LVCOLUMN.fmt.struct = 3
    LVCOLUMN.mask.struct = LVCF.WIDTH OR LVCF.TEXT or LVCF.FMT

    for x=1 to 3
        if x=2 then 'Center justify 2nd column.
            format=LVCFMT.CENTER
            LVCOLUMN.fmt.struct = LVCFMT.CENTER
        end if

        if x=3 then 'Right justify 3rd column.
            format=LVCFMT.RIGHT
            LVCOLUMN.fmt.struct = LVCFMT.RIGHT
        end if

        LVCOLUMN.fmt.struct = format
        LVCOLUMN.cx.struct = columnWidth(x)
        LVCOLUMN.pszText$.struct =columnName$(x)

        call AddColumn hListview1,x-1
   next x

'fill the listview
    n$=chr$(0)
    a$(1)=  "Crude Protein"; n$; "%";     n$; "20.00"
    a$(2)=  "Crude Fat";     n$; "%";     n$; "3.50"
    a$(3)=  "Vitamin A";     n$; "IU/lb"; n$; "4000.00"
    a$(4)=  "Zinc";          n$; "ppm";   n$; "120.00"

    LVITEM.mask.struct = LVIF.TEXT

    for x=1 to 4
        label$  = word$(a$(x),1,n$)
        unit$   = word$(a$(x),2,n$)
        amount$ = word$(a$(x),3,n$)

'1st column info.
        LVITEM.iItem.struct    = x-1     'row
        LVITEM.iSubItem.struct = 0       'column
        LVITEM.pszText$.struct = label$
        call sendLvItemMessageStruct hListview1,LVM.INSERTITEM,0

'2nd column info.
        LVITEM.iSubItem.struct = 1
        LVITEM.pszText$.struct = unit$
        call sendLvItemMessageStruct hListview1,LVM.SETITEM,0

'3rd column info.
        LVITEM.iSubItem.struct = 2
        LVITEM.pszText$.struct = amount$
        call sendLvItemMessageStruct hListview1,LVM.SETITEM,0
    next
wait

[quit.1] 'End the program
    close #1
    END


FUNCTION CreateWindowEx(extended,class$,title$,style,left,top,width,height,hParent,pInst)
    calldll #user32, "CreateWindowExA",_
                      extended as ulong,_
                        class$ as ptr,_
                        title$ as ptr,_
                         style as ulong,_
                          left as ulong,_
                           top as ulong,_
                         width as ulong,_
                        height as ulong,_
                       hParent as ulong,_
                             0 as long,_
                         pInst as ulong,_
                             0 as long,_
                CreateWindowEx as ulong
END FUNCTION

FUNCTION GetWindowLong(hWnd,type)
    calldll #user32, "GetWindowLongA",_
                      hWnd as ulong,_
                      type as long,_
             GetWindowLong as long
END FUNCTION

SUB sendMessage hWnd,msg,wParam,lParam
    calldll #user32, "SendMessageA",_
                      hWnd as ulong, _
                       msg as long,_
                    wParam as long, _
                    lParam as long,_
                         r as long
END SUB

'listview messages
SUB AddColumn hWnd,index
    CallDLL #user32, "SendMessageA",_
                      hWnd as ulong,_
                      4123 as long,_
                     index as long,_
                  LVCOLUMN as struct,_
                         r as long
END SUB

SUB sendLvItemMessageStruct h,m,l
    CallDLL #user32, "SendMessageA",_
                      h as ulong,_
                      m as long,_
                      l as long,_
                 LVITEM as struct,_
                      r as long
END SUB

Sub ListView.SetItemImage hWnd, iItem, iSubItem, iImage
    LVITEM.mask.struct = 2 'LVIF_IMAGE
    LVITEM.iItem.struct = iItem
    LVITEM.iSubItem.struct = iSubItem
    LVITEM.iImage.struct = iImage
    call sendLvItemMessageStruct hWnd,4102,0
End Sub





 


*Modified by Brandon Parker to change the "Quote" tags to "Code" tags for easier viewing of post.*
« Last Edit: May 19th, 2017, 8:06pm by Brandon Parker » User IP Logged

robmcal
Senior Member
ImageImageImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 399
xx Re: ListView Sort
« Reply #1 on: May 19th, 2017, 10:21pm »

I've never worked with a Listview but my best guess would be to use LB to sort the array "a$()" before sending it's contents to the Listview.

Code:
sort a$(), 1, 50 
« Last Edit: May 19th, 2017, 10:23pm by robmcal » User IP Logged

Definition of an Upgrade: Take old bugs out, put new ones in.
tsh73
Board Moderator

member is offline

Avatar

Anatoly (real name)


PM

Gender: Male
Posts: 1688
xx Re: ListView Sort
« Reply #2 on: May 20th, 2017, 3:33pm »

Quote:
how to perform sorting in ListView using api send massage?

MSDN List View Messages
shows three messages
Code:
LVM_SORTGROUPS
LVM_SORTITEMS
LVM_SORTITEMSEX 

Each needs user-defined callback function to be passed.
I wonder if it's possible with LB.
User IP Logged

damned Dog in the Manger
Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2285
xx Re: ListView Sort
« Reply #3 on: May 20th, 2017, 6:35pm »

You CAN create and use callbacks in LB, so it might actually be possible.

(You can't use a full window message hook, because of how fast window messages come in, but it looks like this is different.)

Be interesting to test with, at least.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
NSbrown
New Member
Image


member is offline

Avatar




PM


Posts: 12
xx Re: ListView Sort
« Reply #4 on: May 21st, 2017, 11:57pm »

I can add a button at the top of each cell and sort the data using sort a$(), x, y before inserting it into the table. A little cumbersome code. There seems to be an easier way usung api call back.


Is it possible to get examples of using call window messages to sort ListView?

tnx,
Sharon
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls