Page 1 of 2
What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 7:58 pm
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
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 8:47 pm
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.......
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 9:00 pm
by davido
@charvista,
I Think that the GetGadgetItemData() reads user entered data, by SetGadgetItemData()
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 9:31 pm
by charvista
@davido,
I think you are speaking about GetGadgetItemText().
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 10:04 pm
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?
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 10:27 pm
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
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 10:37 pm
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 ?
Re: What is the best way to save listicongadget colums
Posted: Fri Dec 06, 2013 10:59 pm
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?
Re: What is the best way to save listicongadget colums
Posted: Sat Dec 07, 2013 12:06 am
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
Re: What is the best way to save listicongadget colums
Posted: Sat Dec 07, 2013 1:23 am
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
Re: What is the best way to save listicongadget colums
Posted: Sat Dec 07, 2013 11:33 am
by karu
Many thanks to all

Re: What is the best way to save listicongadget colums
Posted: Mon Dec 09, 2013 2:42 pm
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.
Re: What is the best way to save listicongadget colums
Posted: Mon Dec 09, 2013 4:44 pm
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
Re: What is the best way to save listicongadget colums
Posted: Mon Jan 20, 2014 10:01 pm
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
Re: What is the best way to save listicongadget colums
Posted: Tue Jan 21, 2014 2:34 am
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.