[SOLVED] Multi-column ComboBoxGadget and use of separating delimiter
Posted: Sun Nov 10, 2024 7:24 pm
A delimiting character #LF$ appears to work here, as a means of separating the code from an associated description within the combobox, when we later write it to file.
Is there a better way however, for Windows only?
We have no control over the users' insertion of a space into coded values, nor the length of their codes, otherwise I would obviously just split the value on the space.
Incidentally, I see that multiple-column comboboxes are a frequent requirement and a few other platforms seem to have coded solutions — https://ibb.co/djfd8T4 Perhaps there is something available in PureBasic that I'm not aware of. If there is, I'd be very grateful to know, thanks.
Is there a better way however, for Windows only?
We have no control over the users' insertion of a space into coded values, nor the length of their codes, otherwise I would obviously just split the value on the space.
Incidentally, I see that multiple-column comboboxes are a frequent requirement and a few other platforms seem to have coded solutions — https://ibb.co/djfd8T4 Perhaps there is something available in PureBasic that I'm not aware of. If there is, I'd be very grateful to know, thanks.
Code: Select all
EnableExplicit
; **
; ** Two-column ComboBoxGadget, see line 37
; **
Define counter
Define item, value
Define Event
NewList CodeDesc.s()
AddElement(CodeDesc()) : CodeDesc() = "PINEAPPLE"
AddElement(CodeDesc()) : CodeDesc() = "BANANA"
AddElement(CodeDesc()) : CodeDesc() = "DRAGON FRUIT"
AddElement(CodeDesc()) : CodeDesc() = "STAR FRUIT"
AddElement(CodeDesc()) : CodeDesc() = "MANGO"
AddElement(CodeDesc()) : CodeDesc() = "RAMBUTAN"
AddElement(CodeDesc()) : CodeDesc() = "WATERMELON"
AddElement(CodeDesc()) : CodeDesc() = "POMEGRANATE"
AddElement(CodeDesc()) : CodeDesc() = "LYCHEE"
AddElement(CodeDesc()) : CodeDesc() = "MANGOSTEEN"
AddElement(CodeDesc()) : CodeDesc() = "TAMARIND"
AddElement(CodeDesc()) : CodeDesc() = "PASSION FRUIT"
AddElement(CodeDesc()) : CodeDesc() = "PAPAYA"
If OpenWindow(0, 0, 0, 270, 180, "ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(2, 10, 20, 250, 21)
ForEach(CodeDesc())
counter + 1
; **
; ** Insert delimiter #LF$ to enable ComboBoxGadget value to be extracted without its
; ** associated description
; **
AddGadgetItem(2, -1, "STK" + RSet(Str(counter), 3, "0") + #LF$ + " " + CodeDesc())
Next
SetGadgetState(2, 1)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
item = GetGadgetState(2)
Select EventGadget()
Case 2
If item <> -1
MessageRequester("Stock code", StringField(GetGadgetItemText(2, item), 1, #LF$))
EndIf
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf

