It is currently Mon May 20, 2013 2:29 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: ComboBox whit editable : numberic chr only
PostPosted: Mon May 28, 2012 5:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 03, 2008 9:29 am
Posts: 270
hello
i need a editable combo box whit number input only.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Mon May 28, 2012 6:26 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 972
Location: Anderson Island, WA
Tomi wrote:
hello
i need a editable combo box whit number input only.


Something like this:
http://forum.purebasic.com/english/view ... &view=next


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Mon May 28, 2012 6:51 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
The sRod example limits the input to +integers only:
Code:
#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

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

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 2:54 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 03, 2008 9:29 am
Posts: 270
Many thanks from both, is very useful


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 2:59 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 03, 2008 9:29 am
Posts: 270
Is there a way to remove the tooltip? :?:


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 3:07 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
I don't know how to stop the tooltip, but if you roll your own char check, there won't be a tooltip:
Code:
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.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 3:23 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Different approach
You can adapt it as you like

Code:
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


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 4:38 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
.... or merge the two approaches and you get:
Code:
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.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 5:15 am 
Offline
Addict
Addict

Joined: Sun Apr 12, 2009 6:27 am
Posts: 1468
Back to square one

Code:
#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


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 5:33 am 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
:mrgreen: At this rate, ComboBox is going to need it's very own forum :mrgreen:

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 12:21 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 03, 2008 9:29 am
Posts: 270
Thanks to all, very well :D


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 12:57 pm 
Offline
Addict
Addict

Joined: Tue Feb 22, 2011 1:16 pm
Posts: 1456
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!


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 2:34 pm 
Offline
Addict
Addict

Joined: Fri Oct 23, 2009 2:33 am
Posts: 2852
Location: Wales, UK
Quote:
Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it.

...as does my snippet that allows negative numbers/floats and performs the char-check in the loop. :wink:

_________________
IdeasVacuum
If it sounds simple, you have not grasped the complexity.


Top
 Profile  
 
 Post subject: Re: ComboBox whit editable : numberic chr only
PostPosted: Tue May 29, 2012 4:27 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Sep 03, 2008 9:29 am
Posts: 270
MachineCode wrote:
Don't forget to check for pasted input... the first example in this thread allows the user to paste text into it. ;)

Incidentally, the same across and got help to solve the issue of the ClearClipboard()
Thank you and remind you of discerning
Thank you


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye