AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Listbox Move Sort

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
Jason T
Guest





PostPosted: Fri May 23, 2008 7:04 pm    Post subject: Listbox Move Sort Reply with quote

Hi

Could someone please show me how to sort and move items in a listbox?

I've spent a day searching - but I can't find an example that is simple enough for me to understand.

Thanks

Jason

Code:
#SingleInstance force

IniRead, ListForListBox, Listini.ini, MyValues, Fulllist, 01|02|03|04|05

Gui 14: Add, Text, x20 y20 w300 h40, Here is the list
Gui 14: Add, ListBox, gListbox x20 y60 w350 h250,   
Gui 14: Add, Button, gBtnDelete x390 y70 w100 h40, &Delete
Gui 14: Add, Button, gBtnSort x390 y150 w100 h40, &Sort
Gui 14: Add, Button, gBtnMoveUp x390 y200 w100 h40, &Up
Gui 14: Add, Button, gBtnMoveDown x390 y250 w100 h40, &Down 
Gui 14: Add, Button, gBtnAdd x390 y320 w100 h40, &Add
Gui 14: Add, Text, x20 y320 w100 h40, Class:
Gui 14: Add, Edit, vAbbreviation x120 y320 w250 h40,
Gui 14: Add, Button, gBtnSave Default x120 y380 w110 h40, &Save
Gui 14: Add, Button, gGuiClose x250 y380 w110 h40, &Cancel
Gui 14: Show, h450 w500, Add another one

StringReplace, SeparatedListForListBox, ListForListBox, |, `n, All
Loop, parse, SeparatedListForListBox, `n, `r
{
   If A_index > 0
      Control, Add, %A_LoopField%, Listbox1, A
}


Listbox:
;Get selected item
GuiControlGet, Content, , Listbox1
Return

BtnDelete:
;Delete selected item
GuiControl, 14: +AltSubmit, ListBox1
GuiControlGet, Content, , Listbox1
Control, Delete, %Content%, Listbox1
GuiControl, 14: -AltSubmit, ListBox1
GuiControl, 14: , Edit1; reset to blank
GuiControl, 14: , Edit2; reset to blank
Return

BtnSort:
Msgbox Please help me do this
Return

BtnMoveUp:
Msgbox Please help me do this
Return

BtnMoveDown:
Msgbox Please help me do this
Return

BtnAdd:
NewItem=
GuiControlGet, Content, , Edit1
NewItem=%NewItem%%Content%
ControlGet, List, List,, Listbox1, A
IfInString, List, %NewItem%
   MsgBox, This one is already in your list
else
   Control, Add, %NewItem%, Listbox1, A

Return

BtnSave:
;Do iniwrite
Return

GuiClose:
Return
Back to top
Guest






PostPosted: Fri May 23, 2008 11:03 pm    Post subject: Reply with quote

use a one column listview w/o a header. it has built in functions that will be useful and is alot easier to work with.
Listview has a built in sort
the example in the listview page has a delete label
to save the listview you use something like
Code:
Loop % LV_GetCount()
  {
    LV_GetText(ListItem, A_Index, 1)
    If Not SavedList
      SavedList:=ListItem
    SavedList:=SavedList "|" ListItem
  }

to load
Code:
Loop, Parse, SavedList, |
  LV_Add("", A_LoopField)

to move up: get the row's text, delete the row, and insert(use Lv_Insert()) the text a row above
to move down: move up the row below

you will of course need error checking for the move row up/down or else it wont work
Back to top
joebodo



Joined: 28 Apr 2008
Posts: 45

PostPosted: Sat May 24, 2008 4:03 am    Post subject: Reply with quote

Here's some code I use to sort a listview:

Code:

if (sortDir = "Desc") {
   sortOption := "SortDesc"
} else {
   sortOption := "Sort"
}
LV_ModifyCol(A_Index, sortOption, header)


A_Index is the column to sort
SortOption is either Sort or SortDesc
header is the header text (I believe you can omit this if already set previously)

For moving items in the list, I believe you can try LV_Insert (you probably have to remove the item and then insert it into the correct position).

Alternatively, you can create an hidden index column. To move an item, change the index values for the items you want to switch then re-sort as in the first example.
Back to top
View user's profile Send private message
Jason T
Guest





PostPosted: Sat May 24, 2008 9:11 am    Post subject: Thanks Reply with quote

Thanks for the help

I'll start reading up about listviews Confused

If anyone could point me to a VERY SIMPLE example that I can use as a reference, it may help me.

Thanks again

Jason
Back to top
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Sat May 24, 2008 11:21 am    Post subject: Reply with quote

This does not use a listview, but the listbox.

Code:
BtnSort:
   R := InStr(A_GuiControl, "Rev") ? "R" : ""   ;if reverse sort selected
   Gui, 14:Default
   Gui, 14:+LastFound
   ControlGet, theList, List,, ListBox1
   StringReplace, theList, theList, `n, |, All
   Sort, theList, %R% D|
   GuiControl,, ListBox1, |%theList%
Return

If you want reverse sort, duplicate the 'Sort' button and call it 'Reverse' or 'Rev Sort' (as long as it has 'Rev' in the caption.)

Hope this helps.
_________________
Back to top
View user's profile Send private message
Jason T
Guest





PostPosted: Sat May 24, 2008 1:41 pm    Post subject: ListView Reply with quote

That works!

Also - I've been reading up about Listview, and I agree that that could be the way to go.

Thanks to everyone for the help

Jason
Back to top
Jason T
Guest





PostPosted: Sat May 24, 2008 5:17 pm    Post subject: Need someone with skillz Reply with quote

I've started to play around with listviews, but I'm really struggling.
I would like the selection of a level to change the sublevels.
Also the save button to select one option from each of the three listviews.
I really would like some help Very Happy

Thanks

Jason

Code:
#SingleInstance force

IniRead, Levels, INI.ini, Levels, All6, A|B|C|D|E|F
IniRead, LevelA, INI.ini, SubLevels, 5forA, A1|A2|A3|A4|A5
IniRead, LevelB, INI.ini, SubLevels, 5forB, B1|B2|B3|B4|B5
IniRead, LevelC, INI.ini, SubLevels, 5forC, C1|C2|C3|C4|C5
IniRead, LevelD, INI.ini, SubLevels, 5forD, D1|D2|D3|D4|D5
IniRead, LevelE, INI.ini, SubLevels, 5forE, E1|E2|E3|E4|E5
IniRead, LevelF, INI.ini, SubLevels, 5forF, F1|F2|F3|F4|F5
IniRead, Skill, INI.ini, Skill, Skill, also|and|plus|include
IniRead, Styles, INI.ini, Styles, All4, W|X|Y|Z
IniRead, StyleW, INI.ini, SubStyle, AllforW, W1|W2|W3|W4|W5|W6|W7
IniRead, StyleX, INI.ini, SubStyle, AllforW, X1|X2|X3
IniRead, StyleY, INI.ini, SubStyle, AllforW, Y1|Y2|Y3|Y4|Y5|Y6|Y7|Y8
IniRead, StyleZ, INI.ini, SubStyle, AllforW, Z1|Z2|Z3|Z4|Z5|Z6|Z7


Gui 21: font, s16 c000066 wbold, Arial
Gui 21: +AlwaysOnTop
Gui 21:Default
Gui 21: Add, Text, x20 y20 w300 h40, Mix levels together:
Gui 21: Add, Text, x20 y70 w210 h80 , Choose Levels
Gui 21: Add, DropDownList, x20 y110 w210 h200 vSelectedLevel, %Levels%
Gui 21: Add, ListView, r5 w500 x230 y70 w500 h120 gMyListLevels, Levels
Loop, parse, LevelA, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Text, x20 y200 w210 h80 , Choose Skill
Gui 21: Add, ListView, r4 w500 x230 y200 w500 h120 gMyListSkills, Skill
Loop, parse, Skill, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Text, x20 y330 w210 h80 , Choose Style
Gui 21: Add, DropDownList, x20 y370 w210 h160 , %Styles%
Gui 21: Add, ListView, r5 w500 x230 y330 w500 h160 gStyles, Styles
Loop, parse, StyleW, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Button, gBtnSaveClass Default x230 y500 w110 h40, &Save
Gui 21: Add, Button, g21Guiclose x350 y500 w110 h40, &Cancel
Gui 21: Show, h600 w750, Classes


BtnAdd:
GuiControlGet, NewItemContent, , Edit1
If NewItemContent <>
   LV_Add("", NewItemContent)
Return

BtnSaveClass:
;IniWrite,
Gui 21: Destroy
Return

21Guiclose:
Gui 21: Destroy
Return

MyListLevels:
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.Gui 21: -AlwaysOnTop
Msgbox, 262177, Delete entry, Delete %RowText% from the list?
IfMsgBox OK
   LV_Delete(A_EventInfo)
}
Gui 21: +AlwaysOnTop
return

MyListSkills:
Gui 21: -AlwaysOnTop
Msgbox Not started yet
Gui 21: +AlwaysOnTop
Return

Styles:
Gui 21: -AlwaysOnTop
Msgbox Not started yet
Gui 21: +AlwaysOnTop
Return
Back to top
Micahs



Joined: 01 Dec 2006
Posts: 343

PostPosted: Sun May 25, 2008 2:19 am    Post subject: Reply with quote

This populates the 'level' listview based on the 'level' ddl. Notice the 'SelectLevel' label. Also, you need to add variables to the ddl and listviews you want to manipulate. Hope this gets you started.
Code:
#SingleInstance force

IniRead, Levels, INI.ini, Levels, All6, A||B|C|D|E|F
IniRead, LevelA, INI.ini, SubLevels, 5forA, A1|A2|A3|A4|A5
IniRead, LevelB, INI.ini, SubLevels, 5forB, B1|B2|B3|B4|B5
IniRead, LevelC, INI.ini, SubLevels, 5forC, C1|C2|C3|C4|C5
IniRead, LevelD, INI.ini, SubLevels, 5forD, D1|D2|D3|D4|D5
IniRead, LevelE, INI.ini, SubLevels, 5forE, E1|E2|E3|E4|E5
IniRead, LevelF, INI.ini, SubLevels, 5forF, F1|F2|F3|F4|F5
IniRead, Skill, INI.ini, Skill, Skill, also|and|plus|include
IniRead, Styles, INI.ini, Styles, All4, W|X|Y|Z
IniRead, StyleW, INI.ini, SubStyle, AllforW, W1|W2|W3|W4|W5|W6|W7
IniRead, StyleX, INI.ini, SubStyle, AllforW, X1|X2|X3
IniRead, StyleY, INI.ini, SubStyle, AllforW, Y1|Y2|Y3|Y4|Y5|Y6|Y7|Y8
IniRead, StyleZ, INI.ini, SubStyle, AllforW, Z1|Z2|Z3|Z4|Z5|Z6|Z7


Gui 21: font, s16 c000066 wbold, Arial
Gui 21: +AlwaysOnTop
Gui 21:Default
Gui 21: Add, Text, x20 y20 w300 h40, Mix levels together:
Gui 21: Add, Text, x20 y70 w210 h80 , Choose Levels
Gui 21: Add, DropDownList, x20 y110 w210 h200 vSelectedLevel gSelectLevel, %Levels%
Gui 21: Add, ListView, r5 w500 x230 y70 w500 h120 gMyListLevels vMyListLevels, Levels
Loop, parse, LevelA, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Text, x20 y200 w210 h80 , Choose Skill
Gui 21: Add, ListView, r4 w500 x230 y200 w500 h120 gMyListSkills, Skill
Loop, parse, Skill, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Text, x20 y330 w210 h80 , Choose Style
Gui 21: Add, DropDownList, x20 y370 w210 h160, %Styles%
Gui 21: Add, ListView, r5 w500 x230 y330 w500 h160 gStyles, Styles
Loop, parse, StyleW, |
{
   If A_index > 0
   LV_Add("", A_LoopField)
}

Gui 21: Add, Button, gBtnSaveClass Default x230 y500 w110 h40, &Save
Gui 21: Add, Button, g21Guiclose x350 y500 w110 h40, &Cancel
Gui 21: Show, h600 w750, Classes

Return

SelectLevel:
   Gui, 21:Default
   Gui, Submit, NoHide
   Gui, ListView, MyListLevels
   LV_Delete()
   Loop, parse, Level%SelectedLevel%, |
   {   If A_index > 0
      LV_Add("", A_LoopField)
   }
Return

BtnAdd:
GuiControlGet, NewItemContent, , Edit1
If NewItemContent <>
   LV_Add("", NewItemContent)
Return

BtnSaveClass:
;IniWrite,
Gui 21: Destroy
Return

21Guiclose:
Gui 21: Destroy
Return

MyListLevels:
if A_GuiEvent = DoubleClick
{
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.Gui 21: -AlwaysOnTop
Msgbox, 262177, Delete entry, Delete %RowText% from the list?
IfMsgBox OK
   LV_Delete(A_EventInfo)
}
Gui 21: +AlwaysOnTop
return

MyListSkills:
Gui 21: -AlwaysOnTop
Msgbox Not started yet
Gui 21: +AlwaysOnTop
Return

Styles:
Gui 21: -AlwaysOnTop
Msgbox Not started yet
Gui 21: +AlwaysOnTop
Return

_________________
Back to top
View user's profile Send private message
Guest






PostPosted: Sun May 25, 2008 2:28 am    Post subject: Reply with quote

Quote:
All of the ListView functions operate upon the current thread's default GUI window (which can be changed via Gui, 2:Default). If the default window does not exist or has no ListView controls, all functions return zero to indicate the problem.

If the window has more than one ListView control, by default the functions operate upon the one most recently added. To change this, specify Gui, ListView, ListViewName, where ListViewName is the name of the ListView's associated variable or its ClassNN as shown by Window Spy. Once changed, all existing and future threads will use the indicated ListView.
Back to top
Jason T
Guest





PostPosted: Sun May 25, 2008 10:54 am    Post subject: SORTED !!!! Reply with quote

Thanks for all the help

I've got it working, just the way I wanted.

I'm posting it - and I hope it helps others.

Thanks again

Jason

Code:
#SingleInstance force

IniRead, Levels, INI.ini, Levels, All6, A||B|C|D|E|F
IniRead, A, INI.ini, SubLevels, 5forA, A1|A2|A3|A4|A5
IniRead, B, INI.ini, SubLevels, 5forB, B1|B2|B3|B4|B5
IniRead, C, INI.ini, SubLevels, 5forC, C1|C2|C3|C4|C5
IniRead, D, INI.ini, SubLevels, 5forD, D1|D2|D3|D4|D5
IniRead, E, INI.ini, SubLevels, 5forE, E1|E2|E3|E4|E5
IniRead, F, INI.ini, SubLevels, 5forF, F1|F2|F3|F4|F5
IniRead, Skill, INI.ini, Skill, Skill, also|and|plus|include
IniRead, Styles, INI.ini, Styles, All4, W||X|Y|Z
IniRead, W, INI.ini, SubStyle, AllforW, W1|W2|W3|W4|W5|W6|W7
IniRead, X, INI.ini, SubStyle, AllforW, X1|X2|X3
IniRead, Y, INI.ini, SubStyle, AllforW, Y1|Y2|Y3|Y4|Y5|Y6|Y7|Y8
IniRead, Z, INI.ini, SubStyle, AllforW, Z1|Z2|Z3|Z4|Z5|Z6|Z7


Gui 21: font, s16 c000066 wbold, Arial
Gui 21: +AlwaysOnTop
Gui 21:Default
Gui 21: Add, Text, x20 y20 w300 h40, Mix levels together:
Gui 21: Add, Text, cRed Center x230 y20 w510 h40, Double click one selection from each box below
Gui 21: Add, Text, x20 y70 w210 h80 , Choose Levels
Gui 21: Add, DropDownList, x20 y110 w210 h200 vSelectedLevel gSelectedLevel, %Levels%
Gui 21: Add, ListView, r5 w500 x230 y70 w500 h120 vTopBox gMyListLevels, Levels

Gui 21: Add, Text, x20 y200 w210 h80 , Choose Skill
Gui 21: Add, ListView, r4 w500 x230 y200 w500 h120 vMiddleBox gMyListSkills, Skill


Gui 21: Add, Text, x20 y330 w210 h80 , Choose Style
Gui 21: Add, DropDownList, x20 y370 w210 h160 vSelectedStyles gSelectedStyles , %Styles%
Gui 21: Add, ListView, r5 w500 x230 y330 w500 h160 vBottomBox gStyles, Styles


Gui 21: Add, Button, gBtnSaveClass Default x230 y500 w110 h40, &Save
Gui 21: Add, Button, g21Guiclose x350 y500 w110 h40, &Cancel
Gui 21: Show, h600 w750, Classes

Loop, parse, Skill, |
{
Gui, ListView, MiddleBox
   If A_index > 0
   LV_Add("", A_LoopField)
}

Loop, parse, A, |
{
   If A_index > 0
Gui, ListView, TopBox
   LV_Add("", A_LoopField)
}

Return


SelectedLevel:
GuiControlGet, SelectedLevel, ,SelectedLevel
ListInTopBox := %SelectedLevel%
Gui, ListView, TopBox
LV_Delete()  ; Clear all rows.
Loop, parse, ListInTopBox, |
{
   If A_index > 0
Gui, ListView, TopBox
   LV_Add("", A_LoopField)
}

Loop, parse, W, |
{
   If A_index > 0
Gui, ListView, BottomBox
   LV_Add("", A_LoopField)
}
Return



SelectedStyles:
GuiControlGet, SelectedStyles, ,SelectedStyles
ListInBottomBox := %SelectedStyles%
Gui, ListView, BottomBox
LV_Delete()  ; Clear all rows.
Loop, parse, ListInBottomBox, |
{
   If A_index > 0
Gui, ListView, BottomBox
   LV_Add("", A_LoopField)
}
Return


BtnSaveClass:
;IniWrite,
If FinalLevel =
   {
   Msgbox, 262160, Select a value, You haven't selected anything from the top box.`nEither make a selection of choose CANCEL instead of SAVE
   Return
   }
If FinalSkill =
   {
   Msgbox, 262160, Select a value, You haven't selected anything from the middle box.`nEither make a selection of choose CANCEL instead of SAVE
   Return
   }
If FinalStyle =
   {
   Msgbox, 262160, Select a value, You haven't selected anything from the bottom box.`nEither make a selection of choose CANCEL instead of SAVE
   Return
   }
Gui 21: Destroy
Msgbox Your final selection was: %FinalLevel% %A_Space% %FinalSkill% %A_Space% %FinalStyle%
Return

21Guiclose:
Gui 21: Destroy
Return

MyListLevels:
Gui, ListView, TopBox
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
FinalLevel := RowText
    ToolTip %FinalLevel% from row %A_EventInfo% has been selected
return


return

MyListSkills:
Gui, ListView, MiddleBox
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
FinalSkill := RowText
    ToolTip %FinalSkill% from row %A_EventInfo% has been selected
Return

Styles:
Gui, ListView, BottomBox
    LV_GetText(RowText, A_EventInfo)  ; Get the text from the row's first field.
FinalStyle := RowText
    ToolTip %FinalStyle% from row %A_EventInfo% has been selected
Return
Back to top
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group