how to search through drop down list effectively

Started by davidp@ensuredr.com, November 13, 2019, 07:48:55 AM

Previous topic - Next topic

davidp@ensuredr.com

i have two problems: 1. when typing the drop-down do not opens by itself
2. when typing i'm refreshing the @contents but it is making it difficult to type more than one char because it is getting the focus and overwrite the text

here is the code:

#definefunction ArraySearchResults(originalArray, searchTerm, fieldNumberToSearchIn, useFirstColumnAsHeadlines)
			resultnewList = ""
			resultnew = ArrayFromStr(resultnewList)
			resultnew = ArrDimension(ArrInfo (originalArray, 1) + 1,ArrInfo (originalArray, 2))
			ArrInitialize(resultnew,"null")
			index = 0
			maxIndex = (ArrInfo(originalArray, 1) - 1)
			numberOfTimesExsistsInArray = 0
			if searchTerm == "" || searchTerm == " " then 
				return originalArray
			endif
			for i = 0 to maxIndex
				  exsists = StrIndexNC(originalArray[i, fieldNumberToSearchIn], searchTerm, 0, @FWDSCAN)
				  if useFirstColumnAsHeadlines == @true && i == 0 then
				  		headerNumber = 0
				  		while headerNumber < 15
							resultnew[index,headerNumber] = originalArray[i,headerNumber]
							headerNumber = headerNumber + 1
						EndWhile
				  		index = index + 1
						Continue
				  endif
				  if exsists > 0 then
				  		numberOfTimesExsistsInArray = numberOfTimesExsistsInArray + 1
						rowNumber = 0 
				  		while rowNumber < 15
							resultnew[index,rowNumber] = originalArray[i,rowNumber]
							rowNumber = rowNumber + 1
						EndWhile
						index = index + 1
				  endif
			next
			if numberOfTimesExsistsInArray > 0 then
				return resultnew
			else
				for i = 0 to 15 ; number of items in array
					resultnew[0,i] = "no results"  ;[0,i] if there is no headers else [1,i]
				next
				return resultnew
			endif
#endfunction


arrayList = ArrayFileGetCSV("C:\Users\DavidPeer\Desktop\EDR\CustSRVList.CSV", 0, ",", 0, 0)

originalArray = arrayList

maxIndexForList = ArrInfo(originalArray,1)-1
arrayForList = ArrDimension(maxIndexForList)
for i = 0 to  maxIndexForList
	arrayForList[i] = originalArray[i,1]
next
dlVariable1 = ArrayItemize(arrayForList, @tab)

#DEFINESUBROUTINE TimerProc(MyDialogHandle,MyDialogMessage,MyDialogControlID,MyDialogEventInfo,MyDialogChangeInfo)
	Switch MyDialogMessage
		Case @dePbPush
		
		Case @deInit
	      DialogProcOptions(MyDialogHandle,@deEdText,@TRUE)
			DialogProcOptions(MyDialogHandle,@deDlChange,@TRUE)
			DialogControlSet(MyDialogHandle, "ReportView_1", @dcColWidth  ,-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)
			DialogControlSet(MyDialogHandle, "ReportView_1", @dcContents ,originalArray)
			DialogControlSet(MyDialogHandle, "ReportView_1", @dcColWidth  ,-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1)

	      Return (@retdefault)
	   Case @deEdText
			searcifrchTerm = DialogControlGet(MyDialogHandle, "EditBox_1", @dcText)
			searchTerm = DialogControlGet(MyDialogHandle, "EditBox_1", @dcText)
			resultnew =  ArraySearchResults(originalArray, searchTerm, 1, @true)
			;message("resultnew", ArrayToStr(resultnew))
	      DialogControlSet(MyDialogHandle, "ReportView_1", @dcContents ,resultnew)
			;DialogControlSet(MyDialogHandle, "ReportView_1", @dcRemItem  ,0)
	      Return(@retDefault)

		case @deDlChange
			  searchTerm = DialogControlGet(MyDialogHandle, "DropListBox_1", @dcSelect)
			  resultnew =  ArraySearchResults(originalArray, searchTerm, 1, @true)
			  DialogControlSet(MyDialogHandle, "ReportView_1", @dcContents ,resultnew)

			  maxIndexForList = ArrInfo(resultnew,1) -1
			  arrayForList = ArrDimension(maxIndexForList)
			  dlVariable1 = ""
			  for i = 0 to maxIndexForList
					dlVariable1 = ItemInsert(resultnew[i,1], i, dlVariable1, @tab)
			  next
			  DialogControlSet(MyDialogHandle, "DropListBox_1", @dcContents ,dlVariable1)
			  
			  DialogControlSet(MyDialogHandle, "DropListBox_1", @dcSelect,searchTerm)
			  ;DialogControlState(MyDialogHandle,"ReportView_1", @dcsSetFocus , @true)
			  Return(@retDefault)
	endswitch
#endsubroutine



TimerFormat=`WWWDLGED,6.2`

TimerCaption=`Timer Example`
TimerX=078
TimerY=129
TimerWidth=166
TimerHeight=276
TimerNumControls=005
TimerProcedure=`TimerProc`
TimerFont=`DEFAULT`
TimerTextColor=`DEFAULT`
TimerBackground=`DEFAULT,DEFAULT`
TimerConfig=0
TimerDPI=`96,8,16`

Timer001=`063,123,034,014,PUSHBUTTON,"PushButton_2",DEFAULT,"Cancel",0,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Timer002=`017,025,134,086,REPORTVIEW,"ReportView_1",arrayList,DEFAULT,DEFAULT,40,@csFirstHeader,DEFAULT,DEFAULT,DEFAULT`
Timer003=`035,007,102,012,EDITBOX,"EditBox_1",ebVariable1,"filter",DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Timer004=`013,157,138,114,DROPLISTBOX,"DropListBox_1",dlVariable1,"search",DEFAULT,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
Timer005=`003,157,008,012,PUSHBUTTON,"PushButton_1",DEFAULT,"!",1,50,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("Timer")



thanks
David

td

1.  A DROPLISTBOX is a Windows combo box common control.  Combo boxes have the arrow button for a reason - to control the visibility of the list box part of the control.  That is the way Microsoft designed them to work. You can get the list part of the control to drop when a user starts typing into the edit part of the control by sending a CB_SHOWDROPDOWN message to the control.

2. Not sure which control's input you are referring to but think about it for a second.  How do you know when a user has finished typing into an edit box?  You can know that by responding to every character typed into the control.  Generally, applications wait for the user to signal that they are done by pressing a button or changing the input focus.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

A simple example of sending the CB_SHOWDROPDOWN message:

Code  winbatch Select
#DefineSubroutine ComBoCallbackProc(ComBo_Handle,ComBo_Event,ComBo_Name,ComBo_EventInfo,ComBo_ChangeInfo)
   switch ComBo_Event                                       ; Switch based on Dialog Message type
      case @deInit                                          ; Standard Initialization message
         DialogProcOptions(ComBo_Handle,@deDlChange,@TRUE)
         return(@retDefault)


      case @deDlChange                                     ; ID "DropListBox_1"  dlVariable1
         CB_SHOWDROPDOWN=335
         hWnd = DialogControlGet(Combo_Handle, "DropListBox_1",@dchWnd) 
         SendMessageW(hWnd, CB_SHOWDROPDOWN,1,0)
          
         return(@retDefault)

   endswitch                                                ; ComBo_Event
   return(@retDefault)
#EndSubroutine                                              ; End of Dialog Callback ComBoCallbackProc

dlVariable1 = "1) Tom":@Tab:"2) Bob":@Tab:"3) Tom":@Tab:"4) Ray"

ComBoFormat=`WWWDLGED,6.2`

ComBoCaption=`ComBo Example`
ComBoX=180
ComBoY=144
ComBoWidth=488
ComBoHeight=433
ComBoNumControls=003
ComBoProcedure=`ComBoCallbackProc`
ComBoFont=`DEFAULT`
ComBoTextColor=`DEFAULT`
ComBoBackground=`DEFAULT,DEFAULT`
ComBoConfig=0
ComBoDPI=`192,10,20`

ComBo001=`073,399,049,016,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
ComBo002=`308,399,049,016,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ComBo003=`098,054,261,274,DROPLISTBOX,"DropListBox_1",dlVariable1,DEFAULT,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`

ButtonPushed=Dialog("ComBo")
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Here is another example that uses a hidden context menu item to capture an "enter" keypress as the trigger to indicate the user has finished entering text.  (Meant only as a demo to foster ideas.)

Code  winbatch Select
#DefineSubroutine ComBoCallbackProc(ComBo_Handle,ComBo_Event,ComBo_Name,ComBo_EventInfo,ComBo_ChangeInfo)
   switch ComBo_Event                                       ; Switch based on Dialog Message type
      case @deInit                                          ; Standard Initialization message
         DialogProcOptions(ComBo_Handle,@deDlChange,@TRUE)
         DialogProcOptions(ComBo_Handle,@deMiSelect,@TRUE)         
         return(@retDefault)


      case @deDlChange                                     ; ID "DropListBox_1"  dlVariable1
         CB_SHOWDROPDOWN=335
         hWnd = DialogControlGet(Combo_Handle, "DropListBox_1",@dchWnd) 
         SendMessageW(hWnd, CB_SHOWDROPDOWN,1,0)
         If @csDisabled & DialogControlState(Combo_Handle, 'cmi1_ComBo', @dcsGetStyle, 0)
             DialogControlSet(Combo_Handle, 'cmi1_ComBo', @dcTitle, "\{enter}")  
             DialogControlState(Combo_Handle, 'cmi1_ComBo', @dcsRemStyle, @csDisabled)
         endif
         
         ;;DllCall('user32.dll', long:'ReleaseCapture') 
         return(@retDefault)

      case @deMiSelect                                     ; ID "cmi1_ComBo"  \{enter}
         
         If !(@csDisabled & DialogControlState(Combo_Handle, 'cmi1_ComBo', @dcsGetStyle, 0))
            DialogControlState(Combo_Handle, 'cmi1_ComBo', @dcsAddStyle, @csDisabled)
            DialogControlSet(Combo_Handle, 'cmi1_ComBo', @dcTitle, "\{enter}")  
         endif
         hWnd = DialogControlGet(Combo_Handle, "DropListBox_1",@dchWnd) 
         SendMessageW(hWnd, CB_SHOWDROPDOWN,0,0)
         
         strSelection = DialogControlGet(Combo_Handle, "DropListBox_1", @dcSelect)
         Message('User Selection', strSelection)

         return(@retDefault)

   endswitch                                                ; ComBo_Event
   return(@retDefault)
#EndSubroutine                                              ; End of Dialog Callback ComBoCallbackProc

;============================================================
;============================================================
;============================================================
                                                      
dlVariable1 = "1) Tom":@Tab:"2) Bob":@Tab:"3) Tom":@Tab:"4) Ray"

ComBoFormat=`WWWDLGED,6.2`

ComBoCaption=`ComBo Example`
ComBoX=180
ComBoY=144
ComBoWidth=240
ComBoHeight=185
ComBoNumControls=004
ComBoProcedure=`ComBoCallbackProc`
ComBoFont=`DEFAULT`
ComBoTextColor=`DEFAULT`
ComBoBackground=`DEFAULT,DEFAULT`
ComBoConfig=0
ComBoDPI=`192,10,20`

ComBo001=`020,156,048,016,PUSHBUTTON,"PushButton_OK",DEFAULT,"OK",1,10,@csDefButton,DEFAULT,DEFAULT,DEFAULT`
ComBo002=`161,156,049,016,PUSHBUTTON,"PushButton_Cancel",DEFAULT,"Cancel",0,20,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ComBo003=`022,054,185,071,DROPLISTBOX,"DropListBox_1",dlVariable1,DEFAULT,DEFAULT,30,DEFAULT,DEFAULT,DEFAULT,DEFAULT`
ComBo004=`000,000,000,000,MENUITEM,"cmi1_ComBo","DropListBox_1","",DEFAULT,10,@csDisabled ` ;;@csDisabled 

ButtonPushed=Dialog("ComBo")
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

davidp@ensuredr.com

thanks guys the answers helped me a lot, i also found this helpful for removing the highlight from the edit field: CB_SETEDITSEL

SMF spam blocked by CleanTalk