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.