Reacts to double-click only.. Want single-click.

BlitzMax Forums/BlitzMax Beginners Area/Reacts to double-click only.. Want single-click.

BachFire(Posted 2007) [#1]
This short code works, when I double click on something in the list. I does not react to single-clicks. I can't see how this can be done?

Local MyWindow:TGadget=CreateWindow("no title", 200,200,320,240)
Local List:TGadget=CreateListBox(10,10,200,100,MyWindow)

For Local i=1 To 50
  AddGadgetItem List,i
Next

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_GADGETACTION
     SetStatusText MyWindow, "Clicked on: "+GadgetItemText(List,SelectedGadgetItem(List))
   End Select
Until EventID()=EVENT_WINDOWCLOSE



tonyg(Posted 2007) [#2]
Switch
 Case EVENT_GADGETACTION

with
  Case EVENT_GADGETSELECT 



BachFire(Posted 2007) [#3]
Ah, that's nice. Thanks!


BachFire(Posted 2007) [#4]
I'm thankful for your help, but that does appear to have side-effects after all.. :( If text is inserted in a text area (both manually, and via the program-code), EVENT_GADGETSELECT becomes true. Check this code as it is, and with the REM'ed out line enabled afterwards:

Local MyWindow:TGadget=CreateWindow("no title", 200,200,420,240)
Local List:TGadget=CreateListBox(10,10,75,100,MyWindow)

Local TextBox:TGadget=CreateTextArea(100,10,300,100,MyWindow)	

For Local i=1 To 50
  AddGadgetItem List,i
Next

Rem
AddTextAreaText (TextBox,"This text causes an EVENT_GADGETSELECT")
End Rem

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_GADGETSELECT
     Notify "You (may) have clicked!"
     AddTextAreaText (TextBox,"This sucks!"+Chr$(13))
   End Select
Until EventID()=EVENT_WINDOWCLOSE


Beware, you will have to exit program by force, because there will be no way out. Any way around this? :/


SebHoll(Posted 2007) [#5]
Well, there have been a lot of problems in the past with gadgets generating events when they are changed programatically.

I made a function that allows you to work around these sorts of problems that kills events of a particular type. Don't really know how effecient it is (probably could be better), but it does the job.

Try this for now:
Local MyWindow:TGadget=CreateWindow("no title", 200,200,420,240)
Local List:TGadget=CreateListBox(10,10,75,100,MyWindow)

Local TextBox:TGadget=CreateTextArea(100,10,300,100,MyWindow)	

For Local i=1 To 50
  AddGadgetItem List,i
Next

Rem
AddTextAreaText (TextBox,"This text causes an EVENT_GADGETSELECT")
End Rem

Repeat
  WaitEvent()
  Select EventID()
  Case EVENT_GADGETSELECT
     Notify "You (may) have clicked!"
     AddTextAreaText (TextBox,"This sucks!"+Chr$(13))
	KillEvent(EVENT_GADGETSELECT)
   End Select
Until EventID()=EVENT_WINDOWCLOSE


Function KillEvent(pID%,pID2%=0)
		
		Local tmpList:TList = New TList
		
		PollSystem()
		
		tmpList.AddFirst CurrentEvent;PollEvent
		
		While EventID() <> Null
		
			If Not (EventID() = pID Or EventID() = pID2) Then tmpList.AddLast CurrentEvent		
		
			PollEvent()
		
		Wend
		
		For Local a:TEvent = EachIn tmpList
		
			PostEvent(a)
		
		Next
		
		PollEvent()

EndFunction
If anyone else considers this event generation as a bug, you may want to create a new topic regarding this in the MaxGUI Bug Reports topic.


BachFire(Posted 2007) [#6]
All right. Thanks a lot! ;)