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 

ComboBox List - Setting Value
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
PaulW
Guest





PostPosted: Tue Mar 16, 2010 6:40 pm    Post subject: ComboBox List - Setting Value Reply with quote

[Note: this topic is continued from dropdown list - setting value.]

Hi
I have changed my dropdown list to a ComboBox
FROM:
Code:
Gui,2:Add,Text, xm Section w80, NAME
  Gui,2:Add,Edit, ys-4 w420  vA41, %A31%
  Gui,2:Add,Text, xm Section w80  , EMAIL
  Gui,2:Add,Edit, ys-4 w420  vA42, %A32%
  Gui,2:Add,Text, xm Section w80  , WWW
  Gui,2:Add,Edit, ys-4 w420  vA43, %A33%
  Gui,2:Add,Text, xm Section w80  , COLOR
  Gui,2:Add, DropDownList, ys-4 vA44, aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow
  GuiControl, 2:ChooseString, A44, %A34%
  Gui,2:Add, Button, xm, OK
  Gui,2:Show, , NAME-INPUT


TO:
Code:

  Gui,2:Add,Text, xm Section w80, NAME
  Gui,2:Add,Edit, ys-4 w420  vA41, %A31%
  Gui,2:Add,Text, xm Section w80  , EMAIL
  Gui,2:Add,Edit, ys-4 w420  vA42, %A32%
  Gui,2:Add,Text, xm Section w80  , WWW
  Gui,2:Add,Edit, ys-4 w420  vA43, %A33%
  Gui,2:Add,Text, xm Section w80  , COLOR
  Gui,2:Add, ComboBox, ys-4 vA44, aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow
  GuiControl, 2:ChooseString, A44, %A34%
  Gui,2:Add, Button, xm, OK
  Gui,2:Show, , NAME-INPUT


Now users can add there own color to the list and have it saved into the CSV file.

The results are shown in a listview.
BUT If they edit that entry, the 'new' saved color isn't shown as the default option on color combobox.

If I change the combobox line to list the saved value :
Code:
  Gui,2:Add, ComboBox, ys-4 vA44, %A34%|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow


This works, but gives the potential issue of duplicate entries being shown on the list.. Any way around this ?

Thanks Smile
Back to top
LowBlow
Guest





PostPosted: Tue Mar 16, 2010 7:49 pm    Post subject: Reply with quote

Code:
ColourIndex := "aqua|blackblue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow"

Gui,2:Add, ComboBox, ys-4 vA44, % ColourIndex


MyLable:
GuiControlGet, CBEdit,, A44
If (CBEdit != "") {
   GuiControl,, A44, % CBEdit . "||" . ColourIndex
   FileAppend, % CBEdit . "||" . ColourIndex, My.csv
   }
Else
   <do whatever you like>
Return
Untested.
Back to top
LowBlow
Guest





PostPosted: Tue Mar 16, 2010 7:50 pm    Post subject: Reply with quote

Quote:
This works, but gives the potential issue of duplicate entries being shown on the list.. Any way around this ?
Shocked --> Sort
Back to top
PaulW
Guest





PostPosted: Tue Mar 16, 2010 8:45 pm    Post subject: Reply with quote

LowBlow wrote:
Quote:
This works, but gives the potential issue of duplicate entries being shown on the list.. Any way around this ?
Shocked --> Sort


Sort sorts the list, but I still get the duplicates..

Just about the try the other suggestion.
Back to top
PaulW
Guest





PostPosted: Tue Mar 16, 2010 8:47 pm    Post subject: Reply with quote

LowBlow wrote:
Code:
ColourIndex := "aqua|blackblue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow"

Gui,2:Add, ComboBox, ys-4 vA44, % ColourIndex


MyLable:
GuiControlGet, CBEdit,, A44
If (CBEdit != "") {
   GuiControl,, A44, % CBEdit . "||" . ColourIndex
   FileAppend, % CBEdit . "||" . ColourIndex, My.csv
   }
Else
   <do whatever you like>
Return
Untested.


Can you explain what this does ?? and how I would use it !
Thanks
Back to top
PaulW
Guest





PostPosted: Thu Mar 18, 2010 7:54 pm    Post subject: Reply with quote

Sorry I've tried this but can't get it to work.

All I'm trying to do is have the combo box have no duplicates !
HELP ?
Back to top
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Thu Mar 18, 2010 8:01 pm    Post subject: Reply with quote

PaulW wrote:
Sort sorts the list, but I still get the duplicates..

Your sort requires the U option.
AHK Help File wrote:
U: Removes duplicate items from the list so that every item is unique.
Back to top
View user's profile Send private message Visit poster's website
PaulW
Guest





PostPosted: Thu Mar 18, 2010 8:10 pm    Post subject: Reply with quote

Thanks jaco0646

This is the ComboBox line..
Code:
  Gui,2:Add, ComboBox, ys-4 vA44, %A34%|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow


Adding SortU: (sorry can't find this in the docs !!)

Code:
  Gui,2:Add, ComboBox, ys-4 vA44 SortU, %A34%|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow

And I still see duplicates. !

I know this is caused by having %A34% at the beginning of the list, but there must be a way to resolve that !!

Any Ideas ?
Back to top
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Thu Mar 18, 2010 8:21 pm    Post subject: Reply with quote

Sort
Code:
duplicate = 2
CB_list = %duplicate%|1|2|3|4|5

Gui, Add, ComboBox,,%CB_list%  ;<--Unsorted

Sort, CB_list, U D|
Gui, Add, ComboBox,,%CB_list%  ;<--Sorted

Gui, Show
return
GuiClose:
 ExitApp


Last edited by jaco0646 on Thu Mar 18, 2010 8:26 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Thu Mar 18, 2010 8:21 pm    Post subject: Reply with quote

Are you trying to load the stuff from a CSV file and then display it in a combobox, or the other way round?

Well If you are wanting to only save a new colour if it wasn't already in the list, try the following:
Code:
ColourIndex := "aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow"

  Gui,2:Add,Text, xm Section w80, NAME
  Gui,2:Add,Edit, ys-4 w420  vA41, %A31%
  Gui,2:Add,Text, xm Section w80  , EMAIL
  Gui,2:Add,Edit, ys-4 w420  vA42, %A32%
  Gui,2:Add,Text, xm Section w80  , WWW
  Gui,2:Add,Edit, ys-4 w420  vA43, %A33%
  Gui,2:Add,Text, xm Section w80  , COLOR
  Gui,2:Add, ComboBox, ys-4 vA44, %ColourIndex%
  GuiControl, 2:ChooseString, A44, %A34%
  Gui,2:Add, Button, xm, OK
  Gui,2:Show, , NAME-INPUT
Return

2ButtonOK:
   Gui, 2:Default
   Gui, Submit, Nohide
   GuiControlGet, hA44, Hwnd, A44
   ControlGet, List, List,,, ahk_id %hA44% ; get the list of everything in the combobox (excluding what was typed)

   List .= "`n" . A44 ; add the new colour to the list
   Sort, List, U ; sort it, excluding duplicates

   If ( ErrorLevel )
   {
      MsgBox, Colour "%A44%" probably already exists in the list...
   }
   Else
   {
      MsgBox, Adding new colour "%A44%"

      ; do something here to add it to your CSV or whatever
      StringReplace, List, List, `n, |, All
      GuiControl, , A44, |%List% ; update the combo box to have the new value (is this what you want?)
   }
Return

GuiClose:
GuiEscape:
Esc::
   ExitApp
Return


Are you trying to actually update the ComboBox? You can actually do that too, but it sounds like you want the list to be updated by loading the next time from a CSV or something like that?

Might be useful if you posted the rest of your code... Wink


Edit: Changed some stuff so that the new colour is added to the combo box if it wasn't already in the list (not sure if this is what you wanted?).
Edit2: sinkfaze beat me to it Smile


Last edited by OceanMachine on Thu Mar 18, 2010 8:42 pm; edited 3 times in total
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5043
Location: the tunnel(?=light)

PostPosted: Thu Mar 18, 2010 8:33 pm    Post subject: Reply with quote

Question

Code:
colorList=
(Join
aqua|black|blue|fuchsia|gray|green
|lime|maroon|navy|olive|purple|red
|silver|teal|white|yellow
)
Gui ,2: Add,Text, xm Section w80, Name:
Gui ,2: Add,Edit, xp+60 ys-4 w260  vA41, %A31%
Gui ,2: Add,Text, xm Section w80  , E-Mail:
Gui ,2: Add,Edit, xp+60 ys-4 w260  vA42, %A32%
Gui ,2: Add,Text, xm Section w80  , www.
Gui ,2: Add,Edit, xp+60 ys-4 w260  vA43, %A33%
Gui ,2: Add,Text, xm Section w80  , Color:
Gui ,2: Add, ComboBox, xp+60 ys-4 vA44, %colorList%
Gui ,2: Add, Button, xp+210 yp w50, OK
GuiControl, 2: Choose, A44, 1
Gui ,2: Show, , NAME-INPUT
return

2ButtonOK:
errLvl:=False
Gui, 2: Submit, NoHide
Loop, parse, colorList, |
{
   if RegExMatch(A_LoopField,"^" A44 "$") {
      MsgBox, The color %A44% is already in the list.
      errLvl:=True
      break
   }
}
if errLvl
   return
colorList:=A44 "|" colorList
GuiControl, 2:, A44, |%colorList%
GuiControl, 2: Choose, A44, 1
return

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Thu Mar 18, 2010 8:40 pm    Post subject: Reply with quote

Code:
CB_list = 1|2|3|4|5
Gui, Add, ComboBox, vCB, %CB_list%
Gui, Add, Button, Default, Add Item

Gui, Show
return
GuiClose:
 ExitApp

ButtonAddItem:
 Gui, Submit, NoHide
 CB_list .= "|" CB
 Sort, CB_list, U D|
 GuiControl,,CB, |%CB_list%
return
Back to top
View user's profile Send private message Visit poster's website
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Thu Mar 18, 2010 8:43 pm    Post subject: Reply with quote

Shocked even better jaco0646 Smile
Back to top
View user's profile Send private message
PaulW
Guest





PostPosted: Thu Mar 18, 2010 9:03 pm    Post subject: Reply with quote

Wow !! Thanks for all the replies.

I should have posted this right at the beginning to avoid any.. are you try to do this or that questions...


Code:
#SingleInstance force
   F1=numbermatch.txt
   TestString = 123456,TEST MESSAGE`n
   IfNotExist, %F1%
     FileAppend,%TestString%, %F1%
   Loop,Read,%F1%
     {
       Line%A_Index% := A_LoopReadLine
       Line0 = %A_Index%
     }
   Gui, Add, ListView,grid r15 w320 -Multi -LV0x10 altsubmit vMyListView gMyListView, A|B|C|D|ID
   Gui, Add, Button, x25 y275, Add
   Gui, Add, Button, x159 y275 gDELETE, Delete
   Gui, Add, Button, x299 y275, Update
   
   Gui, Show, ,Number Match
   GoSub,FILLLIST
   return
   Gui, Show, Center w365 h310, Options
   
   
FILLLIST:
  LV_Delete()
  Loop, %Line0%
    {   
      StringSplit, Array, Line%A_Index%, `,
      LV_Add("",Array1,Array2,Array3,Array4,A_Index)
    }
  LV_ModifyCol(1,"75")
  LV_ModifyCol(2,"130")
  LV_ModifyCol(3,"AutoHdr")
  LV_ModifyCol(4,"55")
  LV_ModifyCol(5,"0 Integer")
return

MyListView:
  if A_GuiEvent = DoubleClick
    {
      RowNumber := LV_GetNext(0)
      if not RowNumber
          return
      Loop, 5
          LV_GetText(A3%A_Index%, RowNumber,A_Index)
      editadd = edit
      GoSub,SMGUI
    }
return

SMGUI:
     Gui,3:Add,Text, xm Section w80 , Name
     Gui,3:Add,Edit, ys-4 w220  vA41, %A31%
     Gui,3:Add,Text, xm Section w80  , Email
     Gui,3:Add,Edit, ys-4 w220  vA42, %A32%
     Gui,3:Add,Text, xm Section w80  , wwww
     Gui,3:Add,Edit, ys-4 w220 vA43, %A33%
     Gui,3:Add,Text, xm Section w80, Color
     Gui,3:Add, ComboBox, ys-4 vA44 SORT, %A34%|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|purple|red|silver|teal|white|yellow
     GuiControl, 3:ChooseString, A44, %A34%
     Gui,3:Add, Button, xm, OK
     Gui,3:Show, , TEST
return
 
3ButtonOK:
3GuiClose:
3GuiEscape:
     Gui,3:Submit
     Gui,3:Destroy
     Gui,1:Default
  if editadd = edit
      Line%A35% := A41 . "," . A42 . "," . A43 . "," . A44
  Else
    {
      Line0++
      Line%Line0% := A41 . "," . A42 . "," . A43 . "," . A44
    }
  GoSub,FILLLIST
return

DELETE:
  RowNumber := LV_GetNext(0)
  if not RowNumber
      Return
  Loop, 5
      LV_GetText(A3%A_Index%, RowNumber,A_Index)
 
  Msgbox,4,, Are you sure to delete ?
  Ifmsgbox, No
      return
 
 
  Loop, % Line0 - A35 + 1
    {
      ID := A_Index + A35 - 1
      IDNext := ID + 1
      Line%ID% := Line%IDNext%
    }
  Line0--
  GoSub,FILLLIST
return

ButtonAdd:
  A31=
  A32=
  A33=
  A34=
  editadd=add
  GoSub,SMGUI
return

ButtonUpdate:
  FileContent =
  Loop, %Line0%
      FileContent := FileContent . Line%A_Index% . "`n"
  FileDelete, %F1%
  FileAppend, %FileContent%, %F1%
  Sleep, 500
  ;reload
  Gui, Destroy


As you can from this I have a list view that reads a text file and shows all the entries.

Using a combo box, users can add their own color (name or hex code) and that is updated in the listview and then written to the txt file.

The issue is if I select any of the colors from the list, then go back in and edit it, I get the duplicate entries in the drop down list from the combo box.

Sorry I didn't post this earlier, but how do I resolve that !?
Back to top
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Fri Mar 19, 2010 6:41 am    Post subject: Reply with quote

I've rewritten the script to use an INI file, and hopefully be more readable as well.
Code:
#SingleInstance force
#NoEnv
SetBatchLines -1

f = NumberMatch.ini
IfNotExist, %f%
{ ;Sample data
 IniWrite,  1 , %f%, Count, ID#
 IniWrite, |1|, %f%, Count, list
 IniWrite, John Doe        , %f%, 1, Name
 IniWrite, jd@email.com    , %f%, 1, eMail
 IniWrite, www.johndoe.com , %f%, 1, URL
 IniWrite, aqua            , %f%, 1, Color
}

;Gui 1
Gui, Add, ListView, grid r15 w325 -Multi gLV, ID#|Name|eMail|URL|Color
Gui, Add, Button, w75 xm Default, Add
Gui, Add, Button, wp x+50, Delete
Gui, Add, Button, wp x+50, Edit

;Gui 2
colors = aqua|black|blue|fuchsia|gray|green|lime|maroon
        |navy|olive|purple|red|silver|teal|white|yellow
Gui, 2:+Owner1
Gui, 2:Add, Text, w40, Name:
Gui, 2:Add, Text, wp , eMail:
Gui, 2:Add, Text, wp , URL:
Gui, 2:Add, Text, wp , Color:
Gui, 2:Add, Edit, ym w220 vName
Gui, 2:Add, Edit, wp vEmail
Gui, 2:Add, Edit, wp vURL
Gui, 2:Add, ComboBox, wp vColor, %colors%
Gui, 2:Add, Button, xm+50 w75 Default, OK
Gui, 2:Add, Button, x+20 wp, Cancel

;FillLV
IniRead, list, %f%, Count, list
Loop, Parse, list, |
{
 If !A_LoopField
  continue
 IniRead, name , %f%, %A_LoopField%, Name
 IniRead, email, %f%, %A_LoopField%, eMail
 IniRead, url  , %f%, %A_LoopField%, URL
 IniRead, color, %f%, %A_LoopField%, Color
 LV_Add("",A_LoopField,Name,eMail,URL,Color)
}
LV_ModifyCol(1,0)
Loop,4
 LV_ModifyCol(A_Index+1,"AutoHdr")
;
Gui, Show,,Number Match
return     ;<--End of auto-execute section
GuiClose:
 ExitApp
;
LV:
 If A_GuiEvent != DoubleClick
  return
ButtonEdit:
 RowNumber := LV_GetNext()
 If !RowNumber
  return
 LV_GetText(ID   ,RowNumber,1)
 LV_GetText(name ,RowNumber,2)
 LV_GetText(email,RowNumber,3)
 LV_GetText(url  ,RowNumber,4)
 LV_GetText(color,RowNumber,5)
 Gui, +Disabled
 Gui, 2:Default
 GuiControl,     , Name , %Name%
 GuiControl,     , Email, %eMail%
 GuiControl,     , URL  , %URL%
 GuiControl, Text, Color, %Color%
 Gui, Show,,Edit
return
;
ButtonAdd:
 Gui, +Disabled
 Gui, 2:Default
 GuiControl,,Name
 GuiControl,,Email
 GuiControl,,URL
 GuiControl, Text, Color
 Gui, Show,,Add
return
;
2ButtonOK:
 WinGetActiveTitle, title
 Gui, Submit, NoHide
 If !Name
  return
 Gui, 1:Default
 If (title = "add") {
  IniRead, ID, %f%, Count, ID#
  IniWrite,% ++ID, %f%, Count, ID#
  IniRead, list, %f%, Count, list
  IniWrite,% list ID "|", %f%, Count, list
  LV_Add("",ID,Name,eMail,URL,Color)
 }
 Else LV_Modify(RowNumber,"",ID,Name,eMail,URL,Color)
 IniWrite, %Name%  , %f%, %ID%, Name
 IniWrite, %eMail% , %f%, %ID%, eMail
 IniWrite, %URL%   , %f%, %ID%, URL
 IniWrite, %Color% , %f%, %ID%, Color
2GuiClose:
2ButtonCancel:
 Gui, 1:-Disabled
 Gui, 2:Cancel
return
;
ButtonDelete:
 RowNumber := LV_GetNext()
 If !RowNumber
  return
 Gui, +OwnDialogs
 Msgbox,4, Delete, Are you sure to delete this row?
 IfMsgBox, No
  return
 LV_GetText(ID,RowNumber)
 IniRead, list, %f%, Count, list
 StringReplace, list, list, |%ID%|, |
 IniWrite, %list%, %f%, Count, list
 IniDelete, %f%, %ID%
 LV_Delete(RowNumber)
return
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
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