ListView - Is it possible to sort only specified columns?
For example, a listview contains 10 columns,
LV_ModifyCol(6, "Col4 Col5 SortDesc")
from the code above, the "column 6" shall be DescSorted and "column4/column5" shall be sorted accordingly, but, the others columns shall not be sorted and be kept unchanged.
ListView - Is it possible to sort only specified columns? Topic is solved
Re: ListView - Is it possible to sort only specified columns?
"This function will apply sorting arrows to your ListView column headers"
I didn't mention no arrows, the function didn't help, but thanks anyway.
What I basically wanted to say with the example above is, when "column6" is sorted, only "column4" and "column5" should be sorted along with it, and the other columns should be left unchanged!
Re: ListView - Is it possible to sort only specified columns?
Could you cheat and use 3 listviews?
Otherwise I suppose you would have to capture the clicks onto the column headers, (possibly via OnMessage, or setting the WndProc for the listview control, or maybe AHK can notify you of such clicks via the Gui command,) record the text for the listview before the sort, perhaps via ControlGet, apply the sort to the whole listview, and then restore the text for columns 1 to 3 and 7+.
[EDIT:] Would 1 to 3, and 7 to 10 remain static? Possibly you could have a hidden column 11, containing the original order for those columns. Or you don't even have to retrieve the content for any columns, because you already know what they are at the beginning. Do you have any information to give about the nature of the columns?
Otherwise I suppose you would have to capture the clicks onto the column headers, (possibly via OnMessage, or setting the WndProc for the listview control, or maybe AHK can notify you of such clicks via the Gui command,) record the text for the listview before the sort, perhaps via ControlGet, apply the sort to the whole listview, and then restore the text for columns 1 to 3 and 7+.
[EDIT:] Would 1 to 3, and 7 to 10 remain static? Possibly you could have a hidden column 11, containing the original order for those columns. Or you don't even have to retrieve the content for any columns, because you already know what they are at the beginning. Do you have any information to give about the nature of the columns?
Last edited by jeeswg on 28 Jun 2017, 20:15, edited 3 times in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: ListView - Is it possible to sort only specified columns?
It's a possibility for sure, but I want something more straightforward.jeeswg wrote:.
Re: ListView - Is it possible to sort only specified columns?
ListViews contain rows (items) horizontally split into columns (subitems) in report view. You can access their contents only by row/item number. If you change the vertical order of one/some column(s) independently of the others you change the contents of the rows. It doesn't make sense for me (even though Excel had (has?) such an annoying 'feature').
Re: ListView - Is it possible to sort only specified columns?
+1just me wrote:ListViews contain rows (items) horizontally split into columns (subitems) in report view. You can access their contents only by row/item number. If you change the vertical order of one/some column(s) independently of the others you change the contents of the rows. It doesn't make sense for me (even though Excel had (has?) such an annoying 'feature').
Re: ListView - Is it possible to sort only specified columns? Topic is solved
@jeeswg, I wanted to random sort only the specified columns from a listview control,jeeswg wrote:Do you have any information to give about the nature of the columns?
so I decided to write "ColRandomSort( )" function!
ColRandomSort("1") _ random sorts only column 1
ColRandomSort("2,4") _ random sorts only column 2 and 4
ColRandomSort("13,7,1") _ random sorts only column 13, 7 and 1
and so on...
The function may need more tests, but so far it works with no problems!
Code: Select all
loop, 15
ListCols .= "Test " a_index "|"
gui, add, listview, w700 h250, % ListCols
loop, 10
LV_Add(, a_index "_ " Chr(a_index + 64), a_index "_ " Chr(a_index + 74), a_index "_ " Chr(a_index + 84), a_index "_ " Chr(a_index + 94), a_index "_ " Chr(a_index + 104), a_index "_ " Chr(a_index + 114), a_index "_ " Chr(a_index + 124), a_index "_ " Chr(a_index + 134), a_index "_ " Chr(a_index + 144), a_index "_ " Chr(a_index + 154), a_index "_ " Chr(a_index + 164), a_index "_ " Chr(a_index + 174), a_index "_ " Chr(a_index + 184), a_index "_ " Chr(a_index + 194), a_index "_ " Chr(a_index + 204))
gui, add, button, gSort, Sort 1
gui, add, button, x+5 gSort, Sort 1,2
gui, add, button, x+5 gSort, Sort 1,3
gui, add, button, x+5 gSort, Sort 1,4
gui, add, button, x+5 gSort, Sort 1,2,3,4
gui, add, button, x+5 gSort, Sort 15,1
gui, add, button, x+5 gSort, Sort 14,15
gui, add, button, x+5 gSort, Sort 15
gui, add, button, xm gSort, Sort 2,3
gui, add, button, x+5 gSort, Sort 12
gui, add, button, x+5 gSort, Sort 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
gui, show
return
Sort: ;___________ Sort ____________
if (a_guicontrol = "Sort 1")
ColRandomSort("1")
if (a_guicontrol = "Sort 1,2")
ColRandomSort("1,2")
else if (a_guicontrol = "Sort 1,3")
ColRandomSort("1,3")
else if (a_guicontrol = "Sort 1,4")
ColRandomSort("1,4")
else if (a_guicontrol = "Sort 15,1")
ColRandomSort("15,1")
else if (a_guicontrol = "Sort 14,15")
ColRandomSort("14,15")
else if (a_guicontrol = "Sort 15")
ColRandomSort("15")
else if (a_guicontrol = "Sort 1,2,3,4")
ColRandomSort("1,2,3,4")
else if (a_guicontrol = "Sort 2,3")
ColRandomSort("2,3")
else if (a_guicontrol = "Sort 12")
ColRandomSort("12")
else if (a_guicontrol = "Sort 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")
ColRandomSort("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15")
return
guiclose: ;__________ Gui close ____________
exitapp
ColRandomSort(Cols) ;______________ ColRandomSort(Function) ________________
{
TotalRows := LV_GetCount( ) ;"LV_GetCount( )", returns the total number of rows in the listview control
loop, % TotalRows
{
Random, Rdm1, 1, TotalRows ;"1" is the smallest number and "TotalRows" is the largest number that can be generated
Random, Rdm2, 1, TotalRows ;"Rdm1" and "Rdm2", the variables where to store the random generated numbers
StartPos := 1 ;necessary, otherwise, the function will not work as intended
while, StartPos := RegExMatch(Cols,"\d+", Match, StartPos + StrLen(Match))
{
LV_GetText(Text1, Rdm1, Match) ;"Match" is col, "Rdm1" is row, store in "Text1" variable
LV_GetText(Text2, Rdm2, Match) ;"Match" is col, "Rdm2" is row, store in "Text2" variable
LV_Modify(Rdm1, "col" Match, Text2) ;set "Text2" value in "Rdm1" row from "Match" col
LV_Modify(Rdm2, "col" Match, Text1) ;set "Text1" value in "Rdm2" row from "Match" col
}
}
}
Who is online
Users browsing this forum: Dewi Morgan and 384 guests