is it possible to change Listview rows position/number/index through listview built-in funtions, guicontrol or control commands?
(Obs): I don't want to use the delete/re-insert row method!
Right now I'm using the workaround below, but if there is a better way to do the same thing, please post here!
Code: Select all
count := 20
gui, add, text, , - Select a row and press "F12" to edit its "Id" `n or `n- Select a row, then "Left click" it againt to edit its "Id"
gui, add, listview, h400 BackgroundWhite Grid -ReadOnly gLVLAbel checked, Id|Test
ImageListID := IL_Create(10) ; Create an ImageList to hold 10 small icons.
LV_SetImageList(ImageListID) ; Assign the above ImageList to the current ListView.
Loop 10 ; Load the ImageList with a series of icons from the DLL.
IL_Add(ImageListID, "shell32.dll", A_Index)
Loop 10 ; Add rows to the ListView (for demonstration purposes, one for each icon).
LV_Add("Icon" . A_Index, A_Index, count++)
loop, 2
LV_ModifyCol(a_index, "70") ;width 70
gui, show
return
LVLAbel: ;____________________ Listview Events _______________
if (A_GuiEvent = "e") ;e (lowercase E): The user has finished editing the first field of a row
{
LV_GetText(UserInput, A_EventInfo, 1)
;"A_EventInfo" contains the row number that the user has finished editing the first field
;"1" is the column number
if (InStr(UserInput, ".") = 0) ;if "UserInput" does not contain "." (a dot character), so it is an integer number
{
UserInput := A_EventInfo < UserInput ? UserInput + 0.5 : A_EventInfo > UserInput ? UserInput - 0.5 : UserInput
;Ternary operator, (? = if) and (: = else)
;"A_EventInfo" contains the row number that the user has finished editing the first field
;if EditedtRow < UserInput, UserInput = UserInput + 0.5, else, if EditedtRow > UserInput, UserInput = UserInput - 0.5, else, UserInput = UserInput
LV_Modify(A_EventInfo, "Col1", UserInput)
}
;msgbox, % "Wait: " A_EventInfo " - " UserInput
LV_ModifyCol(1, "Sort Float left")
;"1" column 1
;"Sort", Immediately sorts the column in ascending order (even if it has the Desc option).
;"Float" For sorting purposes, indicates that this column contains floating point numbers (hexadecimal format is not supported). Sorting performance for Float and Text columns is up to 25 times slower than it is for integers.
;"Integer" sorting instead "Float" sort prove to be buggy (not accurate)
;"Left", Left-justifies the column's text
;Update rows index numbers
loop, % LV_GetCount() ;the function returns the total number of rows in the control
LV_Modify(a_index, "Col1", a_index)
}
return
guiclose: ;____________________ gui close ___________________
exitapp
Old Example