What is the best way to save listicongadget colums

Just starting out? Need help? Post your questions and find answers here.
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

What is the best way to save listicongadget colums

Post by karu »

Hi, what is the best way to save listicongadget column order dragged by #PB_ListIcon_HeaderDragDrop, that user if next time open list, gets same column order. To save column names is not the best way i think, especially if app is multilingual. PB4.61

Karu
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What is the best way to save listicongadget colums

Post by charvista »

Good question Karu.
My answer is : I don't know.
I *thought* it could be accomplished with GetGadgetItemData(), but my test returns always 0.

Code: Select all

If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ; left column
    TextGadget    (6,  10,  10, 620, 20, "ListIcon Standard", #PB_Text_Center)
    ListIconGadget(0,  10,  25, 620, 265, "Column 1", 100, #PB_ListIcon_HeaderDragDrop)
    SetGadgetItemData(0,1,1)
    
    For c = 2 To 4
        AddGadgetColumn(0, c, "Column " + Str(c), 65)
        SetGadgetItemData(0,c,c)
    Next
    For r = 0 To 7
        AddGadgetItem(0, r, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
    Next
    
    For i=1 To 4
        Debug GetGadgetItemData(0,i)
    Next
    
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf

The help file says it works with ListIconGadget(), so it is a mystery to me too.......
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: What is the best way to save listicongadget colums

Post by davido »

@charvista,

I Think that the GetGadgetItemData() reads user entered data, by SetGadgetItemData()
DE AA EB
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What is the best way to save listicongadget colums

Post by charvista »

@davido,
I think you are speaking about GetGadgetItemText().
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: What is the best way to save listicongadget colums

Post by karu »

Even user drag columns, getgadgetitemtext get anyway same text from wrong column, so the dragging don't change getgadgettext value, that is the question, how i can understand what column dragged to where?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: What is the best way to save listicongadget colums

Post by RASHAD »

1- After each change to the ListIcon columns order save the new columns order to a file in the user temp directory
2- When you run the program again you should look for your special file
2-1 if the file exist read the columns order into an array col(ColumnCount+1) for exam
2-2 set the columns order using

Code: Select all

          SendMessage_(GadgetID(?), #LVM_SETCOLUMNORDERARRAY, ColumnCount+1, col())
          InvalidateRect_(GadgetID(?),0,1)
         


3- if the file not exist
3-1 create the file
3-2 get the columns order

Code: Select all

   [code]
   SendMessage_(GadgetID(?), #LVM_GETCOLUMNORDERARRAY, ColumnCount+1, col())
   
[/code]
3-3 save the file

You can go from here
Egypt my love
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: What is the best way to save listicongadget colums

Post by karu »

RASHAD wrote:1- After each change to the ListIcon columns order save the new columns order to a file in the user temp directory
2- When you run the program again you should look for your special file
2-1 if the file exist read the columns order into an array col(ColumnCount+1) for exam
2-2 set the columns order using

Code: Select all

          SendMessage_(GadgetID(?), #LVM_SETCOLUMNORDERARRAY, ColumnCount+1, col())
          InvalidateRect_(GadgetID(?),0,1)
         


3- if the file not exist
3-1 create the file
3-2 get the columns order

Code: Select all

   [code]
   SendMessage_(GadgetID(?), #LVM_GETCOLUMNORDERARRAY, ColumnCount+1, col())
   
[/code]
3-3 save the file

You can go from here
Thanks RASHAD, i understand, that after each dragging save column order to file, but i didn't understand how you exactly read column dragged order ?
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What is the best way to save listicongadget colums

Post by charvista »

I tried to follow the advice of RASHAD but no luck so far.

Code: Select all

Enumeration
    #Win
    #Lgad
    #Tgad
    #BtnCheck
EndEnumeration

Dim ColOrder(4)

OpenWindow(#Win,0,0,640,300,"ListIconGadgets",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#Tgad,10,10,620,20,"ListIcon Standard",#PB_Text_Center)
ListIconGadget(#Lgad,10,25,620,200,"Column 1",65,#PB_ListIcon_HeaderDragDrop)

For Col=1 To 3
    AddGadgetColumn(#Lgad,Col,"Column "+Str(Col+1),65)
    SendMessage_(GadgetID(#Lgad),#LVM_SETCOLUMNORDERARRAY,Col,ColOrder())
    InvalidateRect_(GadgetID(#Lgad),0,1)
Next
For Row=0 To 7
    AddGadgetItem(#Lgad,Row,"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
Next


; now give random values to the cells with SetGadgetItemText()
For x = 0 To 7
    For y = 0 To 3
        SetGadgetItemText(#Lgad,x,Chr(Random(25)+65)+Str(Random(9)),y)
    Next y
Next x

ButtonGadget(#BtnCheck,10,250,100,30,"Check")




Repeat
    Event=WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
        ExitEventLoop=#True
    Case #PB_Event_Gadget
        Select EventGadget()
        Case #BtnCheck
            For i=0 To 3
                SendMessage_(GadgetID(#Lgad),#LVM_GETCOLUMNORDERARRAY,i,ColOrder()); get
                Debug ColOrder(i)
            Next i
            Debug GetGadgetItemText(#Lgad,0,0)
        EndSelect
    EndSelect
Until ExitEventLoop
CloseWindow(#Win)
End
I am trying to save the order of the columns in the array ColOrder(), but I don't get any value....
Does the API SendMessage_() fill the array ColOrder() based on the variable Col?
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: What is the best way to save listicongadget colums

Post by RASHAD »

You have to detect the header drop(end of drag) first

Code: Select all

Global OldProc,Flag
Global Dim col(3)


Procedure.i listiconProc(hWnd, uMsg, wParam, lParam)
  Select uMsg
    Case #WM_NOTIFY
      *nmHEADER.HD_NOTIFY = lParam
      Select *nmHEADER\hdr\code        
        Case #HDN_ENDDRAG
           Flag = 1
      EndSelect
  EndSelect
  ProcedureReturn CallWindowProc_(OldProc, hWnd, uMsg, wParam, lParam)
EndProcedure  
  
  
  OpenWindow(0, 100, 100, 500, 400, "Column Order Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 490, 290, "Name :", 100, #PB_ListIcon_HeaderDragDrop|#PB_ListIcon_AlwaysShowSelection| #PB_ListIcon_GridLines )
  OldProc = SetWindowLongPtr_(GadgetID(0), #GWL_WNDPROC, @listIconProc())
  AddGadgetColumn(0, 1, "Gender :", 100)
  AddGadgetColumn(0, 2, "Age :", 100)
  AddGadgetColumn(0, 3, "No. :", 100)
  For x = 1 To 10
     AddGadgetItem(0, -1, "Data "+Str(x)+"-1" + Chr(10) + "Data "+Str(x)+"-2" + Chr(10) + "Data "+Str(x)+"-3" + Chr(10) + "Data "+Str(x)+"-4")
  Next
  
  Repeat

  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
            
           
      Case #WM_LBUTTONUP
           If Flag = 1
              Flag = 0
              SendMessage_(GadgetID(0), #LVM_GETCOLUMNORDERARRAY, 4, col())
              For x = 0 To 3
                Debug col(x)
              Next
            EndIf
            
  EndSelect 

Until Quit = 1
End 
Egypt my love
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What is the best way to save listicongadget colums

Post by charvista »

Thank you RASHAD!
I have also searched my archives and could combine your solution with srod and got this:

Code: Select all

Enumeration
    #Win
    #Lgad
    #Tgad
    #BtnCheck
EndEnumeration

Dim ColOrder(3)

OpenWindow(#Win,0,0,640,300,"ListIconGadgets",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TextGadget(#Tgad,10,10,620,20,"ListIcon Standard",#PB_Text_Center)
ListIconGadget(#Lgad,10,25,620,200,"Column 0",65,#PB_ListIcon_HeaderDragDrop)

For Col=1 To 3
    AddGadgetColumn(#Lgad,Col,"Column "+Str(Col),65)
    SendMessage_(GadgetID(#Lgad),#LVM_SETCOLUMNORDERARRAY,Col,@ColOrder())
    ;InvalidateRect_(GadgetID(#Lgad),0,1)
Next
For Row=0 To 7
    AddGadgetItem(#Lgad,Row,"Item 0"+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3")
Next


ButtonGadget(#BtnCheck,10,250,100,30,"Check")


Repeat
    Event=WaitWindowEvent()
    Select Event
    Case #PB_Event_CloseWindow
        ExitEventLoop=#True
    Case #PB_Event_Gadget
        Select EventGadget()
        Case #BtnCheck
            headerWnd = SendMessage_(GadgetID(#Lgad),#LVM_GETHEADER,0,0)
            numCols = SendMessage_(headerWnd, #HDM_GETITEMCOUNT,0,0)
            Dim ColOrder(numCols-1)
            SendMessage_(GadgetID(#Lgad),#LVM_GETCOLUMNORDERARRAY,numCols,@ColOrder())
            For i=0 To 3
                Debug ColOrder(i)
            Next i
            Debug GetGadgetItemText(#Lgad,0,0)
        EndSelect
    EndSelect
Until ExitEventLoop
CloseWindow(#Win)
End
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
karu
Enthusiast
Enthusiast
Posts: 255
Joined: Fri Jan 13, 2006 12:14 am

Re: What is the best way to save listicongadget colums

Post by karu »

Many thanks to all :)
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: What is the best way to save listicongadget colums

Post by doctorized »

Did anyone try this?

Code: Select all

If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ; left column
    TextGadget    (6,  10,  10, 620, 20, "ListIcon Standard", #PB_Text_Center)
    ListIconGadget(0,  10,  25, 620, 265, "Column 1", 100, #PB_ListIcon_HeaderDragDrop)
    SetGadgetItemData(0,1,1)
   
    For c = 2 To 4
        AddGadgetColumn(0, c, "Column " + Str(c), 65)
        SetGadgetItemData(0,c,c)
    Next
    For r = 0 To 28 Step 4
    	AddGadgetItem(0, r/4, "Item " + Str(1+r) +Chr(10)+"Item " + Str(2+r)+Chr(10)+"Item " + Str(3+r)+Chr(10)+"Item " + Str(4+r))
    Next
   
    For i=0 To 7
    	For j=0 To 3
    		Debug GetGadgetItemText(0,i,j)
    	Next
    Next
   
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
I changed the whole r loop just to show that the correct item was picked.
User avatar
charvista
Addict
Addict
Posts: 949
Joined: Tue Sep 23, 2008 11:38 pm
Location: Belgium

Re: What is the best way to save listicongadget colums

Post by charvista »

@doctorized
I understand, and it is smart, but alas your code does not solve the problem.
Try below your own code on which I added a Check.
Run the program, and click on Check. the line marked with "***" will show "*** Item 20" in the Debug window.
Now move the column 4 to the column 1 with your mouse (drag/drop) because the ListIconGadget() was created with the flag #PB_ListIcon_HeaderDragDrop.
And click on Check again. The debug still shows "*** Item 20" while it had to be now "*** Item 19".

Code: Select all

If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ; left column
    TextGadget    (6,  10,  10, 620, 20, "ListIcon Standard", #PB_Text_Center)
    ListIconGadget(0,  10,  25, 620, 200, "Column 1", 100, #PB_ListIcon_HeaderDragDrop)
    ;SetGadgetItemData(0,1,1)
    
    For c = 2 To 4
        AddGadgetColumn(0, c, "Column " + Str(c), 65)
        ;SetGadgetItemData(0,c,c)
    Next
    For r = 0 To 28 Step 4
        AddGadgetItem(0, r/4, "Item " + Str(1+r) +Chr(10)+"Item " + Str(2+r)+Chr(10)+"Item " + Str(3+r)+Chr(10)+"Item " + Str(4+r))
    Next
    
    ButtonGadget(5,10,230,100,30,"Check")
    
    For i=0 To 7
        For j=0 To 3
            Debug GetGadgetItemText(0,i,j)
        Next
    Next
    
    Repeat
        Event=WaitWindowEvent()
        Select Event
            Case #PB_Event_CloseWindow
                ExitEventLoop=#True
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case 5
                        Debug "*** "+GetGadgetItemText(0,4,3)
                        For i=0 To 7
                            For j=0 To 3
                                Debug GetGadgetItemText(0,i,j)
                            Next
                        Next
                EndSelect
        EndSelect
    Until ExitEventLoop
EndIf
- Windows 11 Home 64-bit
- PureBasic 6.10 LTS (x64)
- 64 Gb RAM
- 13th Gen Intel(R) Core(TM) i9-13900K 3.00 GHz
- 5K monitor with DPI @ 200%
Fenix
Enthusiast
Enthusiast
Posts: 102
Joined: Wed May 07, 2003 1:45 am
Location: Germany

Re: What is the best way to save listicongadget colums

Post by Fenix »

Hi all,

sorry for bringing this back up, but I've got a question about the values returned by the api call and how to interpret them and I didn'T want to open a new topic.

When I take the example of RASHAD and drag column 1 in front of column 0 [1-0-2-3] I get :

4294...
1288...
0
0

When I move column 2 in front of column 1 [0-2-1-3] I get:
8588...
1288...
0
0

First question: Shouldn't there be an ID for every column in the array?
Second question: Why did the ID of column 0 changed from 4294... to 8588... in the second example?

Somehow I don't get it how GETCOLUMNORDERARRAY works :?

Thanks in advance,
Fenix
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: What is the best way to save listicongadget colums

Post by netmaestro »

The most likely reason for getting the results you are seeing is that you're using PB x64. Notice that the col() array is dimmed with no type, which means it will default to .i which is 8 bytes on x64 and the wrong size for the API to output to. The API will write one index every 4 bytes and it has no idea what datatype you used for it. All it cares about is whether it's enough memory or not. It's dumping the first index into the low side of the first element and the second index into the high side of the first element and so on. That's also why your last two elements are always 0 because it's finished dumping before it gets to them. The correct type to use for the array is .l to always have 4-byte elements. Just use Dim col.l(3) and all will be well.
BERESHEIT
Post Reply