Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save or delete item in editable combobox
#5
I defined the relevant code as a subfunction sub.CB_saveDel, but when adding list items, the items added later will overwrite the ones added earlier, Is there a solution?

Macro Macro13
Code:
Copy      Help
ARRAY(str) a
str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 224 136 "Dialog" "4"
;3 ComboBox 0x54230242 0x0 16 8 144 213 ""
;1 Button 0x54030001 0x4 116 116 48 14 "OK"
;2 Button 0x54030000 0x4 168 116 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040C02 "*" "" "" ""

str controls = "3"
str cb3
cb3=
;AAA
;BBB
;Save the current value to the list
;Delete the current list item

a=cb3;;add items into array
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc v
function# hDlg message wParam lParam

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case CBN_SELENDOK<<16|3
,sub.CB_saveDel lParam a
,;_i=CB_SelectedItem(lParam)
,;int i n; str s
,;n=CB_GetCount(lParam)
,;s.getwintext(child("" "Edit" lParam))
,;if(empty(s) or s="Save the current value to the list" or s=" Delete the current list item") ret
,;if _i=n-1 ;;Delete
,,;for(i a.len-1 -1 -1) if(a[i]=s) a.remove(i)
,,;SendMessage(lParam CB_RESETCONTENT 0 0)
,,;for(i 0 a.len) CB_Add(lParam a[i].trim)
,,;CB_SelectItem(lParam 0)
,;if _i=n-2 ;;Save
,,;for(i 0 a.len) if(a[i]=s) ret;;prevent adding identical entry
,,;int index=a.insert(a.len-2)
,,;a[index]=s
,,;SendMessage(lParam CB_RESETCONTENT 0 0)
,,;for(i 0 a.len) CB_Add(lParam a[i].trim)
,,;CB_SelectItem(lParam index)
ret 1

#sub CB_saveDel
function lParam ARRAY(str)a

_i=CB_SelectedItem(lParam)
int i n; str s
n=CB_GetCount(lParam)
s.getwintext(child("" "Edit" lParam))
if(empty(s) or s="Save the current value to the list" or s=" Delete the current list item") ret
if _i=n-1 ;;Delete
,for(i a.len-1 -1 -1) if(a[i]=s) a.remove(i)
,SendMessage(lParam CB_RESETCONTENT 0 0)
,for(i 0 a.len) CB_Add(lParam a[i].trim)
,CB_SelectItem(lParam 0)
if _i=n-2 ;;Save
,for(i 0 a.len) if(a[i]=s) ret;;prevent adding identical entry
,int index=a.insert(a.len-2)
,a[index]=s
,SendMessage(lParam CB_RESETCONTENT 0 0)
,for(i 0 a.len) CB_Add(lParam a[i].trim)
,CB_SelectItem(lParam index)


Messages In This Thread
RE: Save or delete item in editable combobox - by Davider - 03-09-2023, 10:52 AM

Forum Jump:


Users browsing this thread: 4 Guest(s)