ListIconGadget - Moving Nth line Up or Down.
ListIconGadget - Moving Nth line Up or Down.
Hi.
This is a silly question, but I cannot seem to figure out how to move a line in ListIconGadget up or down a position without some work. Isn't there a native command or API? Working with multiple columns and retrieving each and every column text and then deleting the line and reinserting seems like lot of unnecessary work when it should be already convenient.
This is a silly question, but I cannot seem to figure out how to move a line in ListIconGadget up or down a position without some work. Isn't there a native command or API? Working with multiple columns and retrieving each and every column text and then deleting the line and reinserting seems like lot of unnecessary work when it should be already convenient.
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: ListIconGadget - Moving Nth line Up or Down.
Hi Thunder93,
under MS, i've writtem some years ago 2 procedures, MoveRowUp and MoveRowDown.
It's only for 1 selected row. I din't find the code i've written for many raw, sorry.
running OK x86-x64 unicode or not
options are (as parameter):
Here it is, sorry, not good commented, may be it's a beginnig to rewrite somethink better.
and a little example
under MS, i've writtem some years ago 2 procedures, MoveRowUp and MoveRowDown.
It's only for 1 selected row. I din't find the code i've written for many raw, sorry.
running OK x86-x64 unicode or not
options are (as parameter):
Code: Select all
#PB_Rotation = 0 ; --> when selected row is at the top, moverowup will move the row at the end of listicon
; --> when selected row is at the end of listicon, moverowdown will move the row at the begenning of listicon
#PB_NoRotation = 1 ; --> when selected row is at the top, moverowup will not move the row at the end of listicon, row will stay at top
; --> when selected row is at the end of listicon, moverowdown will not move the row at the begenning of listicon, row will stay the end of listicon
Code: Select all
;#PB_ListIcon_Checked ; = 2
;#PB_ListIcon_Selected ; = 1
#PB_SelectAll = $00000002
#PB_UnselectAll = $00000004
#PB_ListIcon_Toggle = $00000001 ; Inverse l'état
#PB_CheckAll = #PB_SelectAll
#PB_UnCheckAll = #PB_UnselectAll
#PB_ToggleCheckBoxes = $00000001 ; Inverse l'état des CheckBox
#PB_ListIcon_Cut = 4
#PB_ListIcon_DragnDrop = 8
#PB_ListIcon_RowFocused = 16
#LVIS_CHECKED = $2000
#LVIS_UNCHECKED = $1000
#PB_CheckRow = %10000000000000000000000000000000
#PB_UnCheckRow = %01000000000000000000000000000000
;#LVIS_STATEIMAGEMASK equ $F000
#LVIS_UnSelected = 0
#PB_ToggleSelectedRows = #PB_ToggleCheckBoxes
#PB_SelectedRow = #PB_CheckRow
#PB_UnSelectedRow = #PB_UnCheckRow
#PB_CutAll = #PB_SelectAll
#PB_UnCutAll = #PB_UnselectAll
#PB_ToggleCutRows = #PB_ToggleCheckBoxes
#LVIS_UnCut = 0
#PB_CutRow = #PB_CheckRow
#PB_UnCutRow = #PB_UnCheckRow
#LVIS_UNDROPHILITED = 0
#PB_DragnDropAll = #PB_SelectAll
#PB_UnDragnDropAll = #PB_UnselectAll
#PB_ToggleDragnDropRows = #PB_ToggleCheckBoxes
#PB_DragnDropRow = #PB_CheckRow
#PB_UnDragnDropRow = #PB_UnCheckRow
#LVIS_UNFOCUSED = 0
#PB_FocusedRow = #PB_CheckRow
#PB_UnFocusedRow = #PB_UnCheckRow
#LVM_SETEXTENDEDLISTVIEWSTYLE = #LVM_FIRST + 54
#LVS_EX_BORDERSELECT = $00008000
#LVS_EX_CHECKBOXES = 4
#LVM_ISITEMVISIBLE = 4278
#PB_Rotation = 0 ; --> when selected row is at the top, moverowup will move the row at the end of listicon
; --> when selected row is at the end of listicon, moverowdown will move the row at the begenning of listicon
#PB_NoRotation = 1 ; --> when selected row is at the top, moverowup will not move the row at the end of listicon, row will stay at top
; --> when selected row is at the end of listicon, moverowdown will not move the row at the begenning of listicon, row will stay the end of listicon
#PB_ShowRow = 2
#PB_ShowRowAtTop = 4
#PB_ShowRowAtBottom = 8
#PB_SelectMovedRow = 16
#PB_SelectOnlyMovedRow = 32
Define .i
EnableExplicit
Declare SwapRows(Gadget, Index1, Index2)
Declare MoveRowUp(Gadget, Row, Option)
Declare MoveRowDown(Gadget, Row, Option)
Declare SetRowMode(Gadget, Option, Ligne)
Procedure SwapRows(Gadget, Index1, Index2)
;// pas de valeur de retour
Protected retour, HeaderID, GadgetID, Nb_Elements, Nb_Elements_plus_Un
Protected Element1.LVITEM, Element2.LVITEM, Element3.LVITEM
Protected *pszText1, *pszText2
Protected Nb_Colonnes, Colonne
#maskLecture = 2335
#StateLecture = 65295
#maskEcriture_SubItem = 3
#maskEcriture_Item = 2335
GadgetID = GadgetID(Gadget)
NB_Elements = SendMessage_(GadgetID, #LVM_GETITEMCOUNT, 0, 0)
If Index1 <> Index2 And Index1 >= 0 And Index2 >= 0 And Index1 < NB_Elements And Index2 < NB_Elements
*pszText1 = AllocateMemory(513*2)
*pszText2 = AllocateMemory(513*2)
If (*pszText1 = 0) Or (*pszText2=0)
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
ProcedureReturn
EndIf
EndIf
HeaderID = SendMessage_(GadgetID, #LVM_GETHEADER, 0, 0)
Nb_Colonnes = SendMessage_(HeaderID, #HDM_GETITEMCOUNT, 0, 0) - 1
For Colonne = 0 To Nb_Colonnes
;// mémorise item Index 1
Element1\mask = #maskLecture
Element1\iItem = Index1
Element1\iSubItem = Colonne
Element1\state = #StateLecture
Element1\stateMask = -1
Element1\pszText = *pszText1
Element1\cchTextMax = 512
SendMessage_(GadgetID, #LVM_GETITEM, 0, @Element1)
;// mémorise item Index 2
Element2\mask = #maskLecture
Element2\iItem = Index2
Element2\iSubItem = Colonne
Element2\state = #StateLecture
Element2\stateMask = -1
Element2\pszText = *pszText2
Element2\cchTextMax = 512
SendMessage_(GadgetID, #LVM_GETITEM, 0, @Element2)
;// on réécrit l'élément Index2 à l'emplacement Index1
If Colonne
Element3\mask = #maskEcriture_SubItem
Else
Element3\mask = #maskEcriture_Item
Element3\state = Element2\state
Element3\stateMask = -1
Element3\lParam = Element2\lParam
Element3\iIndent = Element2\iIndent
Element3\iGroupId = Element2\iGroupId
Element3\cColumns = Element2\cColumns
Element3\puColumns = Element2\puColumns
EndIf
Element3\iItem = Index1
Element3\iSubItem = Colonne
Element3\pszText = *pszText2
Element3\iImage = Element2\iImage
SendMessage_(GadgetID, #LVM_SETITEM, 0, @Element3)
;// on réécrit l'élément Index1 à l'emplacement Index2
If Colonne
Element3\mask = #maskEcriture_SubItem
Else
Element3\mask = #maskEcriture_Item
Element3\state = Element1\state
Element3\stateMask = -1
Element3\lParam = Element1\lParam
Element3\iIndent = Element1\iIndent
Element3\iGroupId = Element1\iGroupId
Element3\cColumns = Element1\cColumns
Element3\puColumns = Element1\puColumns
EndIf
Element3\iItem = Index2
Element3\iSubItem = Colonne
Element3\pszText = *pszText1
Element3\iImage = Element1\iImage
SendMessage_(GadgetID, #LVM_SETITEM, 0, @Element3)
Next Colonne
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
EndProcedure
Procedure MoveRowUp(Gadget, Row, Option)
Protected NB_Elements, Element_Selectionner, Nb_Elements_plus_Un, GadgetID, HeaderID, Pos.POINT
Protected Element1.LVITEM, Element3.LVITEM, Nb_Colonnes
Protected Colonne, prc.RECT
Protected *pszText1, *pszText2
;// Option peut-être une combinaison des valeurs suivantes
;// #PB_Rotation --> l'élément en haut ou bas de liste passera en bas ou en haut de liste
;// #PB_NoRotation --> bloque l'élément en haut ou bas de liste
;// #PB_ShowRow --> affiche toujours la ligne déplacée
;// #PB_ShowRowAtTop --> affiche toujours la ligne déplacée en haut de la liste
;// #PB_SelectMovedRow --> sélectionne la ligne déplacée
If Not(IsGadget(Gadget))
ProcedureReturn
EndIf
GadgetID = GadgetID(Gadget)
If Option & %11111111111111111111111111000000 = #False
Nb_Elements_plus_Un = CountGadgetItems(Gadget)
NB_Elements = Nb_Elements_plus_Un - 1
If NB_Elements ;// on ne move rien s'il n'y a qu'un élément
If Row > 0 And Row <= NB_Elements
SwapRows(Gadget, Row, Row - 1)
If Option & #PB_ShowRow
SendMessage_(GadgetID, #LVM_ENSUREVISIBLE, Row - 2, 0)
ElseIf Option & #PB_ShowRowAtTop
SendMessage_(GadgetID, #LVM_GETITEMPOSITION, Row - 2, Pos)
SendMessage_(GadgetID, #LVM_SCROLL, 0, Pos\y)
EndIf
If Option & #PB_SelectMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | (Row - 1))
SetActiveGadget(Gadget)
ElseIf Option & #PB_SelectOnlyMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_UnSelectAll)
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | (Row - 1))
SetActiveGadget(Gadget)
EndIf
ElseIf Row = 0 ;// On monte, c'est le premier, on le place en dernier
If Option & #PB_NoRotation = #False
*pszText1 = AllocateMemory(513*2)
*pszText2 = AllocateMemory(513*2)
HeaderID = SendMessage_(GadgetID, #LVM_GETHEADER, 0, 0)
Nb_Colonnes = SendMessage_(HeaderID, #HDM_GETITEMCOUNT, 0, 0) - 1
If (*pszText1 = 0) Or (*pszText2=0) Or (Nb_Colonnes = -2)
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
ProcedureReturn
EndIf
For Colonne = 0 To Nb_Colonnes
;// mémorise item Index 1
Element1\mask = #maskLecture
Element1\iItem = Row
Element1\iSubItem = Colonne
Element1\state = #LVIS_OVERLAYMASK | #LVIS_STATEIMAGEMASK | #LVIS_CUT | #LVIS_DROPHILITED | #LVIS_FOCUSED | #LVIS_OVERLAYMASK | #LVIS_SELECTED | #LVIS_STATEIMAGEMASK
Element1\stateMask = -1
Element1\pszText = *pszText1
Element1\cchTextMax = 512
SendMessage_(GadgetID, #LVM_GETITEM, 0, @Element1)
Element3\iItem = Nb_Elements_plus_Un
Element3\iSubItem = Colonne
Element3\pszText = *pszText1
Element3\iImage = Element1\iImage
If Colonne
Element3\mask = #maskEcriture_SubItem
Else
Element3\state = Element1\state
Element3\stateMask = -1
Element3\lParam = Element1\lParam
Element3\iIndent = Element1\iIndent
Element3\iGroupId = Element1\iGroupId
Element3\cColumns = Element1\cColumns
Element3\puColumns = Element1\puColumns
Element3\iSubItem = 0
Element3\mask = #LVIF_TEXT
SendMessage_(GadgetID, #LVM_INSERTITEM, 0, @Element3)
Element3\iSubItem = Colonne
Element3\mask = #maskEcriture_Item
EndIf
SendMessage_(GadgetID, #LVM_SETITEM, 0, @Element3)
If Colonne = Nb_Colonnes
SendMessage_(GadgetID, #LVM_DELETEITEM, 0, 0)
EndIf
Next Colonne
If Option & #PB_ShowRow
SendMessage_(GadgetID, #LVM_ENSUREVISIBLE, Nb_Elements, 0)
ElseIf Option & #PB_ShowRowAtTop
SendMessage_(GadgetID, #LVM_GETITEMPOSITION, Nb_Elements, Pos)
SendMessage_(GadgetID, #LVM_SCROLL, 0, Pos\y)
EndIf
If Option & #PB_SelectMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | Nb_Elements)
SetActiveGadget(Gadget)
ElseIf Option & #PB_SelectOnlyMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_UnSelectAll)
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | Nb_Elements)
SetActiveGadget(Gadget)
EndIf
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
EndIf
EndIf
EndIf
SetActiveGadget(Gadget)
EndIf
EndProcedure
Procedure MoveRowDown(Gadget, Row, Option)
Protected NB_Elements, Element_Selectionner, Nb_Elements_plus_Un, GadgetID, HeaderID, Pos.POINT
Protected Element1.LVITEM, Element3.LVITEM, Nb_Colonnes
Protected Colonne, prc.RECT
Protected *pszText1, *pszText2
;// Option peut-être une combinaison des valeurs suivantes
;// #PB_Rotation --> l'élément en haut ou bas de liste passeera en bas ou en haut de liste
;// #PB_NoRotation --> bloque l'élément en haut ou bas de liste
;// #PB_ShowRow --> affiche toujours la ligne déplacée
;// #PB_ShowRowAtTop --> affiche toujours la ligne déplacée en haut de la liste
;// #PB_SelectMovedRow --> sélectionne la ligne déplacée
If Not(IsGadget(Gadget))
ProcedureReturn
EndIf
GadgetID = GadgetID(Gadget)
If Option & %11111111111111111111111111000000 = #False
Nb_Elements_plus_Un = CountGadgetItems(Gadget)
NB_Elements = Nb_Elements_plus_Un - 1
If NB_Elements ;// on ne move rien s'il n'y a qu'un élément
If Row >= 0 And Row < NB_Elements
SwapRows(Gadget, Row, Row + 1)
Row + 1
If Option & #PB_ShowRow
SendMessage_(GadgetID, #LVM_ENSUREVISIBLE, Row + 1, 0)
ElseIf Option & #PB_ShowRowAtTop
SendMessage_(GadgetID, #LVM_GETITEMPOSITION, Row - 1, Pos)
SendMessage_(GadgetID, #LVM_SCROLL, 0, Pos\y)
EndIf
If Option & #PB_SelectMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | Row)
SetActiveGadget(Gadget)
ElseIf Option & #PB_SelectOnlyMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_UnSelectAll)
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | Row)
SetActiveGadget(Gadget)
EndIf
ElseIf Row = NB_Elements ;// On descend, c'est le dernier, on le place en premier
If Option & #PB_NoRotation = #False
*pszText1 = AllocateMemory(513*2)
*pszText2 = AllocateMemory(513*2)
HeaderID = SendMessage_(GadgetID, #LVM_GETHEADER, 0, 0)
Nb_Colonnes = SendMessage_(HeaderID, #HDM_GETITEMCOUNT, 0, 0) - 1
If (*pszText1 = 0) Or (*pszText2=0) Or (Nb_Colonnes = -2)
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
ProcedureReturn
EndIf
For Colonne = 0 To Nb_Colonnes
;// mémorise item Index 1
Element1\mask = #maskLecture
Element1\iItem = Row
Element1\iSubItem = Colonne
Element1\state = #LVIS_OVERLAYMASK | #LVIS_STATEIMAGEMASK | #LVIS_CUT | #LVIS_DROPHILITED | #LVIS_FOCUSED | #LVIS_OVERLAYMASK | #LVIS_SELECTED | #LVIS_STATEIMAGEMASK
Element1\stateMask = -1
Element1\pszText = *pszText1
Element1\cchTextMax = 512
SendMessage_(GadgetID, #LVM_GETITEM, 0, @Element1)
Element3\iItem = 0
Element3\iSubItem = Colonne
Element3\pszText = *pszText1
Element3\iImage = Element1\iImage
If Colonne
Element3\mask = #maskEcriture_SubItem
Else
Element3\mask = #LVIF_TEXT
SendMessage_(GadgetID, #LVM_INSERTITEM, 0, @Element3)
Row + 1
Element3\mask = #maskEcriture_Item
Element3\state = Element1\state
Element3\stateMask = -1
Element3\lParam = Element1\lParam
Element3\iIndent = Element1\iIndent
Element3\iGroupId = Element1\iGroupId
Element3\cColumns = Element1\cColumns
Element3\puColumns = Element1\puColumns
EndIf
SendMessage_(GadgetID, #LVM_SETITEM, 0, @Element3)
If Colonne = Nb_Colonnes
SendMessage_(GadgetID, #LVM_DELETEITEM, Nb_Elements_plus_Un, 0)
EndIf
Next Colonne
If Option & #PB_ShowRow
SendMessage_(GadgetID, #LVM_ENSUREVISIBLE, 0, 0)
ElseIf Option & #PB_ShowRowAtTop
SendMessage_(GadgetID, #LVM_GETITEMPOSITION, -1, Pos)
SendMessage_(GadgetID, #LVM_SCROLL, 0, Pos\y)
EndIf
If Option & #PB_SelectMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | 0)
SetActiveGadget(Gadget)
ElseIf Option & #PB_SelectOnlyMovedRow
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_UnSelectAll)
SetRowMode(Gadget, #PB_ListIcon_Selected, #PB_SelectedRow | 0)
SetActiveGadget(Gadget)
EndIf
If *pszText1
FreeMemory(*pszText1)
EndIf
If *pszText2
FreeMemory(*pszText2)
EndIf
EndIf
EndIf
EndIf
SetActiveGadget(Gadget)
EndIf
EndProcedure
Procedure.i SetRowMode(Gadget, Option, Ligne)
Protected Nb_elements
Protected GadgetID
Protected StateAll
Protected StateUnAll
Protected Style
Protected i
Protected LigneCocher
Protected item.LVITEM
If IsGadget(Gadget)
GadgetID = GadgetID(Gadget)
Nb_elements = CountGadgetItems(Gadget)-1
Else
ProcedureReturn -1 ; erreur
EndIf
If Nb_elements = -1
ProcedureReturn -1 ; aucun élément dans la liste
EndIf
Select Option
Case #PB_ListIcon_RowFocused
SendMessage_(GadgetID, #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_BORDERSELECT, #LVS_EX_BORDERSELECT)
item.LVITEM\stateMask = #LVIS_FOCUSED
StateAll = #LVIS_FOCUSED
StateUnAll = #LVIS_UNFOCUSED
Case #PB_ListIcon_Checked
item.LVITEM\stateMask = #LVIS_STATEIMAGEMASK
StateAll = #LVIS_CHECKED
StateUnAll = #LVIS_UNCHECKED
Case #PB_ListIcon_Selected
item.LVITEM\stateMask = #LVIS_SELECTED
Style = GetWindowLongPtr_(GadgetID, #GWL_STYLE)
If Style & #LVS_SINGLESEL
SetWindowLongPtr_(GadgetID, #GWL_STYLE, Style & ~#LVS_SINGLESEL)
EndIf
StateAll = #LVIS_SELECTED
StateUnAll = #LVIS_UnSelected
Case #PB_ListIcon_Cut
item.LVITEM\stateMask = #LVIS_CUT
StateAll = #LVIS_CUT
StateUnAll = #LVIS_UnCut
Case #PB_ListIcon_DragnDrop
item.LVITEM\stateMask = #LVIS_DROPHILITED
StateAll = #LVIS_DROPHILITED
StateUnAll = #LVIS_UNDROPHILITED
Default
ProcedureReturn -1
EndSelect
Select Ligne
Case #PB_CheckAll
item.LVITEM\state = StateAll
SendMessage_(GadgetID, #LVM_SETITEMSTATE, -1, item.LVITEM)
ProcedureReturn SendMessage_(GadgetID, #LVM_GETITEMCOUNT, 0, 0)
Case #PB_UnCheckAll
item.LVITEM\state = StateUnAll
SendMessage_(GadgetID, #LVM_SETITEMSTATE, -1, item.LVITEM)
ProcedureReturn 0
Case #PB_ToggleCheckBoxes
For i = 0 To Nb_elements
If SendMessage_(GadgetID, #LVM_GETITEMSTATE, i, StateAll)
item.LVITEM\state = StateUnAll
Else
item.LVITEM\state = StateAll
LigneCocher + 1
EndIf
SendMessage_(GadgetID, #LVM_SETITEMSTATE, i, item.LVITEM)
Next
ProcedureReturn LigneCocher
Default
If Ligne & #PB_CheckRow
item.LVITEM\state = StateAll
ElseIf Ligne & #PB_UnCheckRow
item.LVITEM\state = StateUnAll
Else
ProcedureReturn -1
EndIf
SendMessage_(GadgetID, #LVM_SETITEMSTATE, Ligne & %00111111111111111111111111111111, item.LVITEM)
For i = 0 To Nb_elements
If SendMessage_(GadgetID, #LVM_GETITEMSTATE, i, StateAll)
LigneCocher + 1
EndIf
Next
ProcedureReturn LigneCocher
EndSelect
SetActiveGadget(Gadget)
EndProcedure
Code: Select all
Define .i
Global GLB_event
;// variable mémorisant les différents champs du fichier courant
Global GLB_info.SHFILEINFO
Global Path$ = "C:\"
;// l'ordre des colonnes de l'explorerlist
Enumeration 0
#Colonne_Noms
#Colonne_Attributs
#Colonne_taille
#Colonne_Type
#Colonne_date
EndEnumeration
Enumeration 1
#Listicon
#Button_Up
#Button_Down
EndEnumeration
Enumeration 0
#mainwindow
EndEnumeration
Enumeration 1
#ExamineDirectory
EndEnumeration
CoInitializeEx_(0, #COINIT_APARTMENTTHREADED|#COINIT_SPEED_OVER_MEMORY)
;// xp mini pour comctl32.dll version 6.00 mini
If OSVersion() < #PB_OS_Windows_XP
MessageRequester("Erreur", "OS must be Windows XP at least", #PB_MessageRequester_Ok)
CoUninitialize_()
End
EndIf
;// les thèmes doivent être actifs
If OpenWindow(#mainwindow, 0,0, 980, 670, "ListIconGadget", #PB_Window_MaximizeGadget| #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(#Listicon, 0, 0, WindowWidth(0), WindowHeight(0)/3*2, "Noms", WindowWidth(0)/3, #PB_ListIcon_FullRowSelect|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(#Listicon, 1, "Attributs", GadgetWidth(#Listicon)/6*0.6) ;// Attributs
AddGadgetColumn(#Listicon, 2, "Taille", GadgetWidth(#Listicon)/6*0.9) ;// Taille
AddGadgetColumn(#Listicon, 3, "Type", GadgetWidth(#Listicon)/6) ;// Type
AddGadgetColumn(#Listicon, 4, "Date", 0) ;// Date
SendMessage_(GadgetID(#Listicon), #LVM_SETCOLUMNWIDTH, 4, #LVSCW_AUTOSIZE_USEHEADER)
ButtonGadget(#Button_Up, 20, GadgetY(#Listicon)+GadgetHeight(#Listicon) +20, 100, 30, "Move row Up")
ButtonGadget(#Button_Down, GadgetX(#Button_Up) + GadgetWidth(#Button_Up) +20, GadgetY(#Button_Up), GadgetWidth(#Button_Up), GadgetHeight(#Button_Up), "Move row Down")
Global FileNameOnly$, Attributs, taille$, date$, i
Global SHGetFileInfo, info.SHFILEINFO, attributs$, Times$, type$
If ExamineDirectory(#ExamineDirectory, Path$, "*.*")
While NextDirectoryEntry(#ExamineDirectory)
If DirectoryEntryType(#ExamineDirectory) = #PB_DirectoryEntry_File
FileNameOnly$ = DirectoryEntryName(#ExamineDirectory)
SHGetFileInfo = SHGetFileInfo_(Path$ + FileNameOnly$, 0, @info.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON|#SHGFI_LARGEICON|#SHGFI_TYPENAME|#SHGFI_ATTRIBUTES)
Attributs = DirectoryEntryAttributes(#ExamineDirectory)
attributs$ = " "
If Attributs & (#PB_FileSystem_Archive|#PB_FileSystem_Compressed)
attributs$ = "A"
EndIf
If Attributs & #PB_FileSystem_Normal
attributs$ + "N"
EndIf
If Attributs & #PB_FileSystem_ReadOnly
attributs$ + "R"
EndIf
If Attributs & #PB_FileSystem_System
attributs$ + "S"
EndIf
taille$ = Str((DirectoryEntrySize(#ExamineDirectory)>> 10)+ Bool(((DirectoryEntrySize(#ExamineDirectory)%1024)))) + " Ko"
;// FR
date$ = FormatDate("%dd/%mm/%yyyy %hh:%ii:%ss", DirectoryEntryDate(#ExamineDirectory, #PB_Date_Modified))
If SHGetFileInfo
AddGadgetItem(#Listicon, -1, FileNameOnly$ + Chr(10) + attributs$ + Chr(10) + taille$ + Chr(10) + PeekS(@info\szTypeName[0]) + Chr(10) + date$+Times$, info\hIcon)
DestroyIcon_(info\hIcon)
Else
type$ = "?"
AddGadgetItem(#Listicon, -1, FileNameOnly$ + Chr(10) + attributs$ + Chr(10) + taille$ + Chr(10) + type$+ Chr(10) + date$+Times$)
EndIf
i+1
EndIf
Wend
FinishDirectory(#ExamineDirectory)
EndIf
EndIf
Repeat
GLB_event = WaitWindowEvent()
Select GLB_event
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Up
MoveRowUp(#Listicon, GetGadgetState(#Listicon), #PB_Rotation)
Case #Button_Down
MoveRowDown(#Listicon, GetGadgetState(#Listicon), #PB_NoRotation)
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
CoUninitialize_()
End
A+
Denis
Denis
Re: ListIconGadget - Moving Nth line Up or Down.
Moving by command or by keys Up & Down
Code: Select all
Procedure MoveItem(Gadget,nColumn,iFrom,iTo)
If iFrom > iTo
If iFrom > 0 And iFrom <= CountGadgetItems(Gadget)
AddGadgetItem(Gadget ,iTo-1,"")
For x = 0 To nColumn
SetGadgetItemText(Gadget, iTo-1,GetGadgetItemText(Gadget,iFrom,x),x)
Next
RemoveGadgetItem(Gadget,iFrom)
EndIf
ElseIf iTo > iFrom
If iTo >= 0 And iTo <= CountGadgetItems(Gadget)
AddGadgetItem(Gadget ,iTo,"")
For x = 0 To nColumn
SetGadgetItemText(Gadget, iTo,GetGadgetItemText(Gadget,iFrom-1,x),x)
Next
RemoveGadgetItem(Gadget,iFrom-1)
EndIf
EndIf
SetActiveGadget(Gadget)
EndProcedure
OpenWindow(0, 0, 0, 600, 400, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 580, 340, "Test 1", 150 , #PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines|#PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Test 2", 150)
AddGadgetColumn(0, 2, "Test 3", 120)
AddGadgetColumn(0, 3, "Test 4", 120)
For i = 1 To 10
AddGadgetItem(0, -1, "Line " + Str(i) + " Col 1" + Chr(10) + "Line " + Str(i) + " Col 2"+ Chr(10) + "Line " + Str(i) + " Col 3" + Chr(10) + "Line " + Str(i) + " Col 4")
Next i
ButtonGadget(1,10,370,50,20,"UP")
ButtonGadget(2,65,370,50,20,"DOWN")
MoveItem(0,3,10,9)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Pos = GetGadgetState(0)
If Pos > 0 And Pos <= CountGadgetItems(0)
AddGadgetItem(0 ,Pos - 1,"")
For x = 0 To 3
SetGadgetItemText(0, Pos - 1,GetGadgetItemText(0,Pos+1,x),x)
Next
RemoveGadgetItem(0,Pos+1)
SetGadgetState(0,Pos-1)
EndIf
SetActiveGadget(0)
Case 2
Pos = GetGadgetState(0)
If Pos >= 0 And Pos < CountGadgetItems(0) - 1
AddGadgetItem(0 ,Pos + 2,"")
For x = 0 To 3
SetGadgetItemText(0, Pos + 2,GetGadgetItemText(0,Pos,x),x)
Next
RemoveGadgetItem(0,Pos)
SetGadgetState(0,Pos+1)
EndIf
SetActiveGadget(0)
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
Egypt my love
Re: ListIconGadget - Moving Nth line Up or Down.
Thank you Denis, RASHAD!
I knew it could be done the way RASHAD has it. I thought that I was loosing my mind when I couldn't find a quick and convenient native PB command to-do this. I guess moving lines about in lists isn't so common, or people don't mind a little labour.
I knew it could be done the way RASHAD has it. I thought that I was loosing my mind when I couldn't find a quick and convenient native PB command to-do this. I guess moving lines about in lists isn't so common, or people don't mind a little labour.

ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: ListIconGadget - Moving Nth line Up or Down.
Hi Thunder93
Another approach less headache

Another approach less headache
Code: Select all
Procedure MoveItem(Gadget, iFrom, iTo, nColumn)
iFrom - 1:iTo - 1
For x = 0 To nColumn
Text$ = GetGadgetItemText(Gadget, iFrom, x)
SetGadgetItemText(Gadget, iFrom, GetGadgetItemText(Gadget, iTo, x), x)
SetGadgetItemText(Gadget, iTo, Text$, x)
Next
EndProcedure
OpenWindow(0, 0, 0, 600, 400, "Drag'n drop test", #PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 580, 340, "Test 1", 100 , #PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines| #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Test 2", 100)
AddGadgetColumn(0, 2, "Test 3", 100)
AddGadgetColumn(0, 3, "Test 4", 100)
For i = 1 To 10
AddGadgetItem(0, -1, "Line " + Str(i) + " Col 1" + Chr(10) + "Line " + Str(i) + " Col 2"+ Chr(10) + "Line " + Str(i) + " Col 3" + Chr(10) + "Line " + Str(i) + " Col 4")
Next i
ButtonGadget(1,10,370,50,20,"UP")
ButtonGadget(2,65,370,50,20,"DOWN")
MoveItem(0, 2, 7, 3)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
Pos = GetGadgetState(0)
If Pos > 0 And Pos <= CountGadgetItems(0)
MoveItem(0, Pos+1,Pos, 3)
SetGadgetState(0,Pos-1)
EndIf
SetActiveGadget(0)
Case 2
Pos = GetGadgetState(0)
If Pos >= 0 And Pos < CountGadgetItems(0) - 1
MoveItem(0, Pos+1,Pos+2, 3)
SetGadgetState(0,Pos+1)
EndIf
SetActiveGadget(0)
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
Egypt my love
Re: ListIconGadget - Moving Nth line Up or Down.
Hi RASHAD!
Even though your previous one and this here latest one you giving processes all in 0 milliseconds, this here latest one shows simplicity. Less code and under the hood possibly less processing involved?
Your previous MoveItem procedure code I made some small changes, even though it was good as-is.
Now with your latest, I'll use that instead. Thank you very much.
Also I'm very happy what Denis posted, that was awesome and gives me options depending on what I'm doing. Thank you both!
Even though your previous one and this here latest one you giving processes all in 0 milliseconds, this here latest one shows simplicity. Less code and under the hood possibly less processing involved?
Your previous MoveItem procedure code I made some small changes, even though it was good as-is.
Code: Select all
Procedure MoveItem(Gadget,nColumn,iFrom,iTo)
Colmns$ = ""
If iFrom > iTo
If iFrom > 0 And iFrom <= CountGadgetItems(Gadget)
; AddGadgetItem(Gadget ,iTo-1,"")
For x = 0 To nColumn
Colmns$ + GetGadgetItemText(Gadget,iFrom-1,x) + Chr(10)
Next
; SetGadgetItemText(Gadget, iTo-1,"TestTest1",x)
AddGadgetItem(Gadget ,iTo-1,Colmns$)
RemoveGadgetItem(Gadget,iFrom)
EndIf
ElseIf iTo > iFrom
If iTo >= 0 And iTo <= CountGadgetItems(Gadget)
; AddGadgetItem(Gadget ,iTo,"")
For x = 0 To nColumn
Colmns$ + GetGadgetItemText(Gadget,iFrom-1,x) + Chr(10)
Next
; SetGadgetItemText(Gadget, iTo,Colmns$,x)
AddGadgetItem(Gadget ,iTo,Colmns$)
RemoveGadgetItem(Gadget,iFrom-1)
EndIf
EndIf
SetActiveGadget(Gadget)
EndProcedure
Also I'm very happy what Denis posted, that was awesome and gives me options depending on what I'm doing. Thank you both!
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: ListIconGadget - Moving Nth line Up or Down.
Here's MoveItem procedure now.

Code: Select all
Procedure MoveItem(Gadget, iFrom, iTo, nColumn)
Text$ = "" : Text2$ = ""
iFrom - 1:iTo - 1
For x = 0 To nColumn
Text$ + GetGadgetItemText(Gadget, iFrom, x) + Chr(10)
Text2$ + GetGadgetItemText(Gadget, iTo, x) + Chr(10)
; SetGadgetItemText(Gadget, iFrom, GetGadgetItemText(Gadget, iTo, x), x)
; SetGadgetItemText(Gadget, iTo, Text$, x)
Next
SetGadgetItemText(Gadget, iFrom, Text2$)
SetGadgetItemText(Gadget, iTo, Text$)
EndProcedure
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
Re: ListIconGadget - Moving Nth line Up or Down.
Hi guys, do you have any luck with multiple lines?
I'm stuck on this.

▌│█║▌║▌ █║║▌║█
Re: ListIconGadget - Moving Nth line Up or Down.
Move Multiple Lines
- Adjust Auto-Move speed by changing the AddWindowTimer (Timeout)
*** Includes a Callback / Timer - adding the ability to move items by holding down the buttons ***
- Adjust Auto-Move speed by changing the AddWindowTimer (Timeout)
*** Includes a Callback / Timer - adding the ability to move items by holding down the buttons ***
Code: Select all
Global lpPrevWndFunc
Procedure SetText(Gadget, posFrom.i, posTo.i, ColumnCount.i)
For rtnCount = 0 To ColumnCount - 1
lvText + GetGadgetItemText(Gadget, posFrom, rtnCount) + Chr(10)
Next
SendMessage_(GadgetID(Gadget), #WM_SETREDRAW, #False, 0)
RemoveGadgetItem(Gadget, posFrom)
AddGadgetItem(Gadget, posTo, lvText)
PostMessage_(GadgetID(Gadget), #WM_SETREDRAW, #True, 0)
SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, posTo, 0)
EndProcedure
Procedure MoveItems(Gadget, Direction.i, ColumnCount.i)
SetActiveGadget(Gadget)
If Direction < 0
lvFlags = #LVNI_BELOW | #LVNI_SELECTED
lvIndex.i = GetGadgetState(Gadget)
Else
lvFlags = #LVNI_ABOVE | #LVNI_SELECTED
TotalItems.i = CountGadgetItems(Gadget) - 1
If GetGadgetItemState(Gadget, TotalItems) = 1 : SetText(Gadget, TotalItems - 1, TotalItems - 2, 4) : EndIf
lvIndex.i = SendMessage_(GadgetID(Gadget), #LVM_GETNEXTITEM, TotalItems, lvFlags)
EndIf
While lvIndex >= 0
SetText(Gadget, lvIndex, lvIndex + Direction, ColumnCount)
SetGadgetItemState(Gadget, lvIndex, 0)
SetGadgetItemState(Gadget, lvIndex + Direction, 1)
lvIndex = SendMessage_(GadgetID(Gadget), #LVM_GETNEXTITEM, lvIndex, lvFlags)
Wend
EndProcedure
Procedure GadgetCallback(hWnd, Msg, wParam, lParam)
Select Msg
Case #WM_LBUTTONDOWN
AddWindowTimer(0, hWnd, 100)
Case #WM_LBUTTONUP
RemoveWindowTimer(0, hWnd)
EndSelect
ProcedureReturn CallWindowProc_(lpPrevWndFunc, hWnd, Msg, wParam, lParam)
EndProcedure
If OpenWindow(0, 0, 0, 400, 390, "Move Multiple Items", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 380, 345, "Test 1", 85, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Test 2", 85)
AddGadgetColumn(0, 2, "Test 3", 85)
AddGadgetColumn(0, 3, "Test 4", 85)
ButtonGadget(1, 10, 360, 70, 20, "Move Up")
ButtonGadget(2, 320, 360, 70, 20, "Move Down")
ColumnHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
ColumnCount.i = SendMessage_(ColumnHeader, #HDM_GETITEMCOUNT, 0, 0)
lpPrevWndFunc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @GadgetCallback())
lpPrevWndFunc = SetWindowLong_(GadgetID(2), #GWL_WNDPROC, @GadgetCallback())
For rtnCount = 1 To 40
ListItem.s = ""
For newCount = 1 To ColumnCount
ListItem + "Line " + Str(rtnCount) + " Col " + Str(newCount) + Chr(10)
Next
AddGadgetItem(0, -1, ListItem)
Next
SetWindowTitle(0, "Move Multiple Items: " + Str(CountGadgetItems(0)))
lvStyle = SendMessage_(GadgetID(0), #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
lvStyle + #LVS_EX_DOUBLEBUFFER | #LVS_EX_LABELTIP
SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lvStyle)
SetActiveGadget(0)
SetGadgetItemState(0, 0, 1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If GetGadgetItemState(0, 0) <> 1 : MoveItems(0, -1, ColumnCount) : EndIf
Case 2
If GetGadgetItemState(0, CountGadgetItems(0) - 1) <> 1 : MoveItems(0, 1, ColumnCount) : EndIf
EndSelect
Case #PB_Event_Timer
If EventTimer() = GadgetID(1)
If GetGadgetItemState(0, 0) <> 1 : MoveItems(0, -1, ColumnCount) : EndIf
Else
If GetGadgetItemState(0, CountGadgetItems(0) - 1) <> 1 : MoveItems(0, 1, ColumnCount) : EndIf
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
Last edited by JHPJHP on Wed Jul 17, 2013 9:30 pm, edited 6 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
Re: ListIconGadget - Moving Nth line Up or Down.
Move Multiple Lines
I liked how RASHAD accomplished the task of moving an item, so I incorporated his approach with my previous post:
(my previous post uses add/remove, RASHAD's approach is to replace text)
- Adjust Auto-Move speed by changing the AddWindowTimer (Timeout)
*** Includes a Callback / Timer - adding the ability to move items by holding down the buttons ***
I liked how RASHAD accomplished the task of moving an item, so I incorporated his approach with my previous post:
(my previous post uses add/remove, RASHAD's approach is to replace text)
- Adjust Auto-Move speed by changing the AddWindowTimer (Timeout)
*** Includes a Callback / Timer - adding the ability to move items by holding down the buttons ***
Code: Select all
Global lpPrevWndFunc
Procedure SetText(Gadget, posFrom.i, posTo.i, ColumnCount.i)
For rtnCount = 0 To ColumnCount - 1
lvText1 + GetGadgetItemText(Gadget, posFrom, rtnCount) + Chr(10)
lvText2 + GetGadgetItemText(Gadget, posTo, rtnCount) + Chr(10)
Next
SetGadgetItemText(Gadget, posFrom, lvText2)
SetGadgetItemText(Gadget, posTo, lvText1)
SendMessage_(GadgetID(Gadget), #LVM_ENSUREVISIBLE, posTo, 0)
EndProcedure
Procedure MoveItems(Gadget, Direction.i, ColumnCount.i)
SetActiveGadget(Gadget)
If Direction < 0
lvFlags = #LVNI_BELOW | #LVNI_SELECTED
lvIndex.i = GetGadgetState(Gadget)
Else
lvFlags = #LVNI_ABOVE | #LVNI_SELECTED
TotalItems.i = CountGadgetItems(Gadget) - 1
If GetGadgetItemState(Gadget, TotalItems) = 1 : SetText(Gadget, TotalItems - 1, TotalItems - 2, 4) : EndIf
lvIndex.i = SendMessage_(GadgetID(Gadget), #LVM_GETNEXTITEM, TotalItems, lvFlags)
EndIf
While lvIndex >= 0
SetText(Gadget, lvIndex, lvIndex + Direction, ColumnCount)
SetGadgetItemState(Gadget, lvIndex, 0)
SetGadgetItemState(Gadget, lvIndex + Direction, 1)
lvIndex = SendMessage_(GadgetID(Gadget), #LVM_GETNEXTITEM, lvIndex, lvFlags)
Wend
EndProcedure
Procedure GadgetCallback(hWnd, Msg, wParam, lParam)
Select Msg
Case #WM_LBUTTONDOWN
AddWindowTimer(0, hWnd, 100)
Case #WM_LBUTTONUP
RemoveWindowTimer(0, hWnd)
EndSelect
ProcedureReturn CallWindowProc_(lpPrevWndFunc, hWnd, Msg, wParam, lParam)
EndProcedure
If OpenWindow(0, 0, 0, 400, 390, "Move Multiple Items", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ListIconGadget(0, 10, 10, 380, 345, "Test 1", 85, #PB_ListIcon_MultiSelect | #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect | #PB_ListIcon_AlwaysShowSelection)
AddGadgetColumn(0, 1, "Test 2", 85)
AddGadgetColumn(0, 2, "Test 3", 85)
AddGadgetColumn(0, 3, "Test 4", 85)
ButtonGadget(1, 10, 360, 70, 20, "Move Up")
ButtonGadget(2, 320, 360, 70, 20, "Move Down")
ColumnHeader = SendMessage_(GadgetID(0), #LVM_GETHEADER, 0, 0)
ColumnCount.i = SendMessage_(ColumnHeader, #HDM_GETITEMCOUNT, 0, 0)
lpPrevWndFunc = SetWindowLong_(GadgetID(1), #GWL_WNDPROC, @GadgetCallback())
lpPrevWndFunc = SetWindowLong_(GadgetID(2), #GWL_WNDPROC, @GadgetCallback())
For rtnCount = 1 To 40
ListItem.s = ""
For newCount = 1 To ColumnCount
ListItem + "Line " + Str(rtnCount) + " Col " + Str(newCount) + Chr(10)
Next
AddGadgetItem(0, -1, ListItem)
Next
SetWindowTitle(0, "Move Multiple Items: " + Str(CountGadgetItems(0)))
lvStyle = SendMessage_(GadgetID(0), #LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
lvStyle + #LVS_EX_DOUBLEBUFFER | #LVS_EX_LABELTIP
SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lvStyle)
SetActiveGadget(0)
SetGadgetItemState(0, 0, 1)
Repeat
Select WaitWindowEvent()
Case #PB_Event_Gadget
Select EventGadget()
Case 1
If GetGadgetItemState(0, 0) <> 1 : MoveItems(0, -1, ColumnCount) : EndIf
Case 2
If GetGadgetItemState(0, CountGadgetItems(0) - 1) <> 1 : MoveItems(0, 1, ColumnCount) : EndIf
EndSelect
Case #PB_Event_Timer
If EventTimer() = GadgetID(1)
If GetGadgetItemState(0, 0) <> 1 : MoveItems(0, -1, ColumnCount) : EndIf
Else
If GetGadgetItemState(0, CountGadgetItems(0) - 1) <> 1 : MoveItems(0, 1, ColumnCount) : EndIf
EndIf
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
EndIf
Last edited by JHPJHP on Wed Jul 17, 2013 9:31 pm, edited 4 times in total.
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.