This Question is Answered

15 "helpful" answers available (3 pts)
4 Replies Last post: Aug 28, 2008 6:14 AM by varshuj

Regarding RecordGrid Events

Aug 27, 2008 6:35 AM

Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008

Hi,

How to consume some event say Event1 which will be fired after or before a Event2, So How Event1 to be consumed in Event2.

For example :

In recordgrid first selectionevent is fired and then ContextMenuEvent is fired.
Can we cosume selectionevent while executing ContextMenuEvent


Thanks,

Varsha

Click to view Duke's profile Curl Duke 154 posts since
Oct 17, 2007
1. Re: Regarding RecordGrid Events Aug 27, 2008 3:08 PM
I think the SelectionEvent is processed and consumed before the ContextMenuEvent fires. On Windows, ContextMenuEvent is fired on PointerRelease.
What is it that you are trying to do? Are you trying to stop the SelectionEvent from happening when doing right click?
Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
2. Re: Regarding RecordGrid Events Aug 27, 2008 9:29 PM
in response to: Duke

yes,

when i right click on RecordGrid ContextMenuEvent should be processed and SelectionEvent should be consumed.

I dont want SelectionEvent to be processed when i right click on RecordGrid.


Thanks,

Varsha

Click to view fukuta's profile BlackBelt fukuta 105 posts since
Oct 17, 2007
3. Re: Regarding RecordGrid Events Aug 28, 2008 1:32 AM
in response to: varshuj
I'm not sure I understand what you really want to do, but if you just don't want to handle the SelectionEvent caused by right click on a RecordGrid, how about doing like this?

{let right-clicked?:bool = false}
{RecordGrid
    record-source = your-records,
    height = 3cm,
    {on e:PointerEnvelopeEvent do
        {type-switch e.contents
         case pp:PointerPress do
            {if pp.button == right-button then
                set right-clicked? = true
                {after 0s do
                    set right-clicked? = false
                }
            }
        }
    },
    {on e:SelectionEvent do
        {if not right-clicked? then
            {popup-message "selection event fired"}
        }
    }
}

This sample set a flag when right click and reset it in a {after 0s do}, while the SelectionEvent handler checks the flag to see if the event is caused by right click. Note that we can watch a PointerEnvelopeEvent to catch a PointerPress on the RecordGrid.
I think it may be that you are trying not to change row or other selections of a RecordGrid when doing right click. If so, it can be done using similar idea. The example below shows you how to do it.

{let indices:#IntVec = null}
{let restoring?:bool = false}
{RecordGrid
    record-source = your-records,
    height = 3cm,
    {on e:PointerEnvelopeEvent at grid:RecordGrid do
        {type-switch e.contents
         case pp:PointerPress do
            def selection = grid.selection
            {if pp.button == right-button and
                not selection.empty?
             then
                set indices = {IntVec {splice selection.records}}
            }
        }
    },
    {on e:SelectionChanged at grid:RecordGrid do
        {if restoring? then {return}}
        {if-non-null iv = indices then
            {with restoring? = true do
                {grid.select-nothing}
                {for i in iv do
                    {grid.select-record i, additive? = true}
                }
            }
            set indices = null
        }
    }
}

The idea is that it saves the selected records on a right click and restores it when SelectionChanged event coming from right click. In addition, another flag named restoring? is used to avoid a endless occurring of a SelectionChanged. This sample does nothing for columns or regions selection for the sake of simplicity. So you might need some work to support those selections.
Click to view varshuj's profile Level 3 varshuj 44 posts since
Mar 6, 2008
4. Re: Regarding RecordGrid Events Aug 28, 2008 6:14 AM
in response to: fukuta

Thanks fukuta :)