Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

BindEvent( ) for an object added at runtime

Status
Not open for further replies.

CrimsonJio

Programmer
Nov 23, 2011
6
0
0
PH
Hi guys,

I have a problem with the an event I binded to the When method I created using AddObject( ).

Below is what I did:
1. call AddObject( ) - to create a combo box in my grid
2. call BindEvent( ) - to bind Event1 to the When method of the created object

However, when I run my form, the binded event does not fire immediately when I focus on the added object.

Am I missing something?

TIA
 
Have set the column's CurrentControl property to the combo box? And have you made the combo box visible? Either of those two could affect the firing of the When.

More generally, have you checked that the When is actually firing as expected? In other words, you should determine if the problem is caused by the BindEvents or the actual firing of the When.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Yes, all properties have been set.

When I select the combo box, the binded event does not fire. It will fire only after I have selected a value in the combo box.
 
Yes, that's what I would expect. From the Help:

VFP Help for When Event said:
.. the When event occurs each time a user moves the focus between items in the list by clicking on items or by moving the selection with the arrow keys.

If that's not what you want, you need to bind to the GotFocus rather than the When.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
From the help topic on BINDEVENT(): "Certain events such as When and Valid require code in the event for it to occur."

So does your combobox class has code in When? If you take the native combobox, bindevent won't be triggered.

Bye, Olaf.

 
Mike, doesn't the When event fire prior to the object actually receiving the focus?

Olaf, I'm using the native combo box... dang...
 
It's not hard to change that to a combobox class with when code. And then you can most probably also do without the Bindevent. Or bind to GotFocus(). If you want to return .f. or do NODEFAULt in when, you can only do that in the when itself anyway, a bound method won't return .f. on behalf of when.

It's the simpler solution anyway, in your situation. As you add comboboxes programmatical you can easily choose another than the native combobox.
If the grid would already have native comboboxes in it's columns, it would be harder to change, not impossible, but harder. would help.

That's just one of the manyfold reasons to never use the native classes themselves, but pick from a lib with subclassed controls _combobx or mycombobox eg for the combobox. Then you alkways have a place to interpcept by changing properties or adding code. People tend to fear that is too global, they'd need to test everything in their app to still work after a central change inherited everywhere. But these base classes are not ther to implement very specific local needs, you would eg add a * in the when event and then you have code. And that would have no influence whatsoever on everything else.

Bye, Olaf.
 
Mike, doesn't the When event fire prior to the object actually receiving the focus?

With most controls, that's right. But for listboxes and combo boxes, it fires when you change the selection, either by scrolling through the list with the mouse or with the arrow keys. (Which is exactly what the Help that I quoted says.)

If you want an event that fires when the control gets focus, use the GotFocus.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
Mike,

in my help, only the listbox is mentioned to repeat the When event in case you pick a listitem or move in them. But it's plausible, that this also happens in the combobox. I think it's mainly because picking an item the whole stack of events is triggered: valid, lostfocus, when, and gotfocus. Haven't tested that.

If you want to return .f. from WHEN to prevent usage of the combobox in the grid, then you better do that in your own subclass. But you could also simpler SET RELATION from the grid alias to the lookup table feeding the combobox items, instead of using the combobox, and then set the textbox controlsource to that other tables field you want to display only.

For instance:
SELECT bills
SET RELATION TO customerid INTO customers (which is set to index order id)
then set grid.columnX.text1.controlsource = "customers.name" to display the name from the customers table instead of the bills.customerid. You don't need a combobox for that.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top