Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Save or delete item in editable combobox
#1
Hi,

I need to save or delete entries in editable combobox controls. I have seen similar controls in many software. How can I implement them in QM? The following code only implements some functions 
Current problem: I can't get the text in the edit box at the same time, save and reload the items
[Image: 1678011956]
 
Thanks in advance for any suggestions and help
david

Macro Macro8
Code:
Copy      Help
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
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
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
,_i=CB_SelectedItem(lParam)
,CB_GetItemText(lParam _i _s)
,int n=CB_GetCount(lParam)
,if _i=n-1 ;;Dele
,,mes "Line -1"
,,mes _s
,if _i=n-2 ;;Save
,,mes "Line -2"
,,mes _s
ret 1
#2
this will get you going in the right direction
add and remove work

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
,_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
#3
Thanks for your help, 
 
Sorry, I forgot some description, I want to store the modified list somewhere, so that after the software restarts, it can still be used 
 
Where is it saved? System variable? Registry? Ini file? Which method is most suitable?

e.g:
GetEnvVar("bak_items" bak_items)

SetEnvVar("bak_items" bak_items)
#4
saves to registry

Code:
Copy      Help
str cb3t Mname
Mname.getmacro("" 1)
rget cb3t "cb3t" F"\{Mname}"
if cb3t.len=0
,cb3t=
,;AAA
,;BBB
,;Save the current value to the list
,;Delete the current list item

ARRAY(str) a
a=cb3t;;add items into arra
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=cb3t

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
,Mname.getmacro("" 1)
,cb3t=a; cb3t.trim
,rset cb3t "cb3t" F"\{Mname}"
,case IDCANCEL
,Mname.getmacro("" 1)
,cb3t=a; cb3t.trim
,rset cb3t "cb3t" F"\{Mname}"    
,case CBN_SELENDOK<<16|3
,_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
#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)
#6
Change
 
Code:
Copy      Help
function lParam ARRAY(str)a
 
to
 
Code:
Copy      Help
function lParam ARRAY(str)&a
#7
thank you


Forum Jump:


Users browsing this thread: 1 Guest(s)