onRecordSelection

I’d like to to something onRecordSelection in table view, but only when the user clicks on a line, not when a method changes the current record. Any known trick?

Note really… but you could use a form var as a switch, you disable the switch at the beginning of your methods and re-enable it at the end. In the onRecSelection you perform your logic only if the switch is true (user clicked the rec). Just out of my head.

onRecordSelection also gets the event object passed as argument.
function event.getSource() should give you some indication of what happens.

mboegem:
onRecordSelection also gets the event object passed as argument.
function event.getSource() should give you some indication of what happens.

Good hint! I’m still not used to 5.2… still thinking the 4.1 way, I’ll need to reshape my mind… :)

ngervasi:
Good hint! I’m still not used to 5.2… still thinking the 4.1 way, I’ll need to reshape my mind… :)

That would be a good pre-/post-conference session for ServoyWorld 2011 :wink:
After the holiday season we need to get in shape anyway, so let’s reshape completely :)

Any volunteers for drillmaster?

using the switch does not seem to work, it seems the onrecordselection is done before the form var is set.
using the event does not work either, the event is the same for a method and a user selection in table view.

For the switch approach you can use a global var instead of the form var, let me check theevent, I think it’s possible to use just that.

lesouef:
using the event does not work either, the event is the same for a method and a user selection in table view

hmmm, I’ve seen differences between the 2 calls, but I think it’ll also depend on the code.

Can you maybe give some more background on what you are trying to achieve.
Maybe there’s another way to get there.

the question that pops up in my mind, why are you changing the selection through code?
This is purely to set the ui to the next record and nothing more?
Why then is it that you dont want to do stuff in the onrecordselection? What is different for this case?

correct, I have an onLoad or onShow method very often which changes the default record to something else than the 1st, or after search, i often set the last record active.
and this triggers the onRecordSelection too with no event difference, the source is the form. Of course I can work in list mode and place an object underneath, but I’d like to use the table mode and still be able to distinguish a user action from a method, like an onRowClick…

lesouef:
correct, I have an onLoad or onShow method very often which changes the default record to something else than the 1st, or after search, i often set the last record active.
and this triggers the onRecordSelection too with no event difference, the source is the form. Of course I can work in list mode and place an object underneath, but I’d like to use the table mode and still be able to distinguish a user action from a method, like an onRowClick…

ok, this sounds quite normal so far.
as Johan asked: what is in the onRecordSelection method that can’t be triggered when the onLoad/onShow is setting your record?

We have this all the time and there’s no problem at all…

Yep, +1

Like in Foxpro the events :

grid.beforeRowColChangeEvent() and
grid.afterRowColChangeEvent()

Servoy : Duplicate all the foxpro UI-events into Servoy and all is well… :wink:

Regards,

I have this case in several places:
for example, if I want to display another form upon onRecordSelection. thefore I only want this upon user action.
or prompt a message if a specific record cannnot be selected for an action which starts by a onDrag.

what you can do now is make sure that the foundsets selection is set correctly before pushing it in the form that has that onrecordselection event
If you do it before then the onrecordselection won’t be set.

Also if the foundset is already shown in the form what you could do (but this could have some side effects) is to replace the foundset first with a empty foundset
change the selection, and set that foundset back in. But you have to test how that works out in the ui…

another thing that could be done and should work is have a form variable:

var selectionset = false;

function ichangeselection()
{
    selectionset = true;
    foundset.setSelectedIndex(1)
   selectionset = false;
}

function onrecordselection()
{
   if (selectionset) return;
   //
}

It could be that the selection event is not quite in the same order fired (so it is really fired after the ichangeselection method) then change your code to this:

var selectionset = false;

function ichangeselection()
{
    selectionset = true;
    foundset.setSelectedIndex(1)
}

function onrecordselection()
{
   if (selectionset) {
       selectionset = false;
    return;
    }
   //
}

I have tested the form var solution, but I must modify all methods which change the current record, that is sort, find/seach, etc…, and it’s easy to forget one. On top I have many global methods doing this too, etc…
the major pb is that some default form actions like sorting a column by clicking its header, nextrecord, etc… must also be changed to take this form var into account.
so too much work, making a list view instead of a table view is quicker and safer, but I think it would be good to have a rowclick event or so, same choice as button, right click, double click; what do you think, shall post a feature req for this?

i think there is already a case for that, but you could add a case so that we can add/attach this to that one.

not really a case, more a feature request?
I have also tried the event source track, but I then discovered that it is not coherent for table views at least:
the 1st click may return a different source object than the 2nd if you have objects in the form header.
in my case, the header has fields for searching data:
once the form is on screen, after onload + onshow, etc… the 1st click returns the search filter field name, and the second click “formscope” instead of returning formscope twice.