Storing a value in a button

BlitzMax Forums/BlitzMax Programming/Storing a value in a button

Fry Crayola(Posted 2006) [#1]
Is it possible in any way to store a value in a button, as well as its text?

I want to be able to click a buttont to bring up a search box which will allow me to pick one of thousands of items. A combo box isn't ideal because there are too many items to make that usable. The search box would also allow for a text-based search.

Upon clicking OK in the search box, I'd like to be able to store the value of the selected item, as well as the text representing it, in the button for later retrieval.

Or is it not possible? My alternate method is to use an object in which I can store the value, which is probably just as good, but the button method would be cleaner.

Cheers.


degac(Posted 2006) [#2]
well, you could use the context method to store this information (it can be a string,int or a type...)


Fry Crayola(Posted 2006) [#3]
Context method? I've never heard of that...

Any examples?


degac(Posted 2006) [#4]
' createbutton.bmx

Strict 

Local window:TGadget
Local button:TGadget[5]

Type myinfo
	Field info1:String="boo"
End Type

window=CreateWindow("MaxGui Buttons",40,40,240,300,Null,WINDOW_TITLEBAR)
button[0]=CreateButton("Push Button",10,10,140,24,window,BUTTON_PUSH)
button[1]=CreateButton("Checkbox Button",10,34,140,24,window,BUTTON_CHECKBOX)
button[2]=CreateButton("Radio Button",10,58,140,24,window,BUTTON_RADIO)
button[3]=CreateButton("OK",10,82,70,24,window,BUTTON_OK)
button[4]=CreateButton("Cancel",84,82,70,24,window,BUTTON_CANCEL)

button[0].context="This is my additional information"

Local other_info:myinfo=New myinfo
other_info.info1="HAllo world"

button[1].context=other_info



While True
	WaitEvent 
	Select EventID()
		Case EVENT_WINDOWCLOSE
			End
		Case EVENT_GADGETACTION
			If EventSource()=button[0]
				Print "Context "+String(button[0].context)
			End If
			
			If EventSource()=button[1]
				Local con:myinfo=myinfo(button[1].context)
				Print "Context "+con.info1
			End If
						
			Print "EVENT_GADGETACTION"
	End Select
Wend


Of course you need to specify (to cast) the object you want to store in the general context:object