ComboBox whit editable : numberic chr only
ComboBox whit editable : numberic chr only
hello
i need a editable combo box whit number input only.
i need a editable combo box whit number input only.
Re: ComboBox whit editable : numberic chr only
Something like this:Tomi wrote:hello
i need a editable combo box whit number input only.
http://forum.purebasic.com/english/view ... &view=next
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ComboBox whit editable : numberic chr only
The sRod example limits the input to +integers only:
If you need to handle negative values or floats/doubles, listen for #PB_EventType_Change on the combo and test the input char.
Edit: Changed Set/Get WindowLong to WindowLongPtr
Code: Select all
#ES_NUMBER=$2000
If OpenWindow(0, 0, 0, 270, 440, "Test ComboBoxGadget",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 20, #PB_ComboBox_Editable)
;--> Get the handle to the Edit control (child of the editable ComboBoxGadget)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
SetWindowLongPtr_(hComboEdit, #GWL_STYLE, GetWindowLongPtr_(hComboEdit, #GWL_STYLE) | #ES_NUMBER)
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
Edit: Changed Set/Get WindowLong to WindowLongPtr
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ComboBox whit editable : numberic chr only
Many thanks from both, is very useful
Re: ComboBox whit editable : numberic chr only
Is there a way to remove the tooltip? 

-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ComboBox whit editable : numberic chr only
I don't know how to stop the tooltip, but if you roll your own char check, there won't be a tooltip:
Code: Select all
Procedure Win()
;--------------
If OpenWindow(0, 0, 0, 200, 140, "Combo Numbers",#PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
ComboBoxGadget(1,10, 10,180,20,#PB_ComboBox_Editable)
AddGadgetItem(1,-1,"10")
AddGadgetItem(1,-1,"20")
EndIf
EndProcedure
Procedure WaitForUser()
;---------------------
sInput.s = ""
sNumber.s = ""
sChar.s = ""
Repeat
iEvent.i = WaitWindowEvent(1)
Select iEvent
Case #PB_Event_Gadget
If((EventGadget() = 1) And (EventType() = #PB_EventType_Change))
sInput = GetGadgetText(1)
iLen = Len(sInput)
sNumber = ""
For iCnt = 1 To iLen
sChar = Mid(sInput,iCnt,1)
iAscii = Asc(sChar)
iIncludeChar = #True
Select iAscii
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ;Accepted numbers
Case 45, 46 ; Minus sign, accepted delimiter
Default: iIncludeChar = #False
EndSelect
If((iAscii = 45) And (iCnt > 1)) : iIncludeChar = #False : EndIf
If(iIncludeChar = #True) : sNumber = sNumber + sChar : EndIf
Next
iLen = (Len(sNumber) + 1)
SetGadgetText(1,"")
SetGadgetText(1,sNumber)
SendMessage_(GadgetID(1),#CB_SETEDITSEL,iLen,iLen)
SendMessage_(GadgetID(1),#CB_SETEDITSEL,-1,-1)
EndIf
EndSelect
Until iEvent = #PB_Event_CloseWindow
EndProcedure
;###Main Entry Point
Win()
WaitForUser()
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ComboBox whit editable : numberic chr only
Different approach
You can adapt it as you like
You can adapt it as you like
Code: Select all
Global ComboGadgetSC
Procedure ComboGadgetProc(hWnd,uMsg,wParam,lParam)
Select uMsg
Case #WM_CHAR
If (wParam < 48 And wParam <> 8) Or wParam > 57
ProcedureReturn 0
EndIf
EndSelect
ProcedureReturn CallWindowProc_(ComboGadgetSC,hWnd,uMsg,wParam,lParam)
EndProcedure
If OpenWindow(0, 0, 0, 270, 440, "Test ComboBoxGadget",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 20, #PB_ComboBox_Editable)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
ComboGadgetSC = SetWindowLongPtr_(hComboEdit,#GWL_WNDPROC,@ComboGadgetProc())
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
End
Egypt my love
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ComboBox whit editable : numberic chr only
.... or merge the two approaches and you get:
Code: Select all
Global gComboGadgetSC.i
Procedure ComboGadgetProc(hWnd,uMsg,wParam,lParam)
;------------------------------------------------
Select uMsg
Case #WM_CHAR
Select wParam
Case 48, 49, 50, 51, 52, 53, 54, 55, 56, 57 ;Accepted numbers
Case 45, 46 ; Minus sign, accepted delimiter
Default: ProcedureReturn 0
EndSelect
EndSelect
ProcedureReturn CallWindowProc_(gComboGadgetSC,hWnd,uMsg,wParam,lParam)
EndProcedure
Procedure Win()
;--------------
If OpenWindow(0, 0, 0, 270, 140, "ComboBox Floats",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(1, 10, 10, 250, 20, #PB_ComboBox_Editable)
ihComboEdit = FindWindowEx_(GadgetID(1), #Null, "Edit", #Null)
gComboGadgetSC = SetWindowLongPtr_(ihComboEdit,#GWL_WNDPROC,@ComboGadgetProc())
AddGadgetItem(1, -1, "123")
AddGadgetItem(1, -1, "456")
AddGadgetItem(1, -1, "789")
AddGadgetItem(1, -1, "EDIT ME")
SetGadgetState(1,3)
EndIf
EndProcedure
Win()
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ComboBox whit editable : numberic chr only
Back to square one
Code: Select all
#ES_NUMBER=$2000
If OpenWindow(0, 0, 0, 270, 200, "Test ComboBoxGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ComboBoxGadget(0, 10, 10, 250, 24, #PB_ComboBox_Editable)
;--> Get the handle to the Edit control (child of the editable ComboBoxGadget)
hComboEdit = FindWindowEx_(GadgetID(0), #Null, "Edit", #Null)
SetWindowLong_(hComboEdit, #GWL_STYLE, GetWindowLong_(hComboEdit, #GWL_STYLE) | #ES_NUMBER)
AddGadgetItem(0, -1, "123")
AddGadgetItem(0, -1, "456")
AddGadgetItem(0, -1, "789")
AddGadgetItem(0, -1, "EDIT ME")
SetGadgetState(0,0)
Repeat
If IsGadget(0)
SendMessage_(hComboEdit, #EM_HIDEBALLOONTIP, 0, 0)
EndIf
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
EndIf
End
Egypt my love
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ComboBox whit editable : numberic chr only


IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ComboBox whit editable : numberic chr only
Thanks to all, very well 

-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: ComboBox whit editable : numberic chr only
Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it. 

Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: ComboBox whit editable : numberic chr only
...as does my snippet that allows negative numbers/floats and performs the char-check in the loop.Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it.

IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: ComboBox whit editable : numberic chr only
Incidentally, the same across and got help to solve the issue of the ClearClipboard()MachineCode wrote:Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it.
Thank you and remind you of discerning
Thank you