This is a migrated thread and some comments may be shown as answers.

Multiple cell selection and context menu

1 Answer 72 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mats
Top achievements
Rank 1
Mats asked on 03 Dec 2012, 04:12 PM
Hi!

I have a grid with multiple cell selection enabled - CellSelectionMode="MultiCell".

It works great when I select multiple cells. But when I right click on one of the selected cells to bring up a context menu then all cells will be deselected except the on that I right click.

I want all selected cells to stay selected when I right click on a selected cell. Is it possible to cancel the deselecting in this case?

Thanks
/Mats

1 Answer, 1 is accepted

Sort by
0
Mats
Top achievements
Rank 1
answered on 05 Dec 2012, 12:24 PM
Solved it by cancelling the 'OnCellSelecting' and 'OnCellDeselecting' events if the cell that is right clicked is already selected.
Added jscript and client settings for the grid.
function cellIsSelected(element) {
    if (element) {
        if (element.className.indexOf("rgSelectedCell") >= 0)
            return true;
        else
            return cellIsSelected(element.parentElement);
    }
    return false;
}
 
function rightButtonClicked(e) {
    if (!e) e = new Sys.UI.DomEvent(window.event);
    if ((e.type == 'mousedown') || (e.type == 'mouseup'))
        return e.button > 0;
    return false;
}
 
function cellSelecting(sender, args) {
    var e = new Sys.UI.DomEvent(window.event);
    if (rightButtonClicked(e) && cellIsSelected(e.target))
        args.set_cancel(true);
}
 
function cellDeselecting(sender, args) {
    var e = new Sys.UI.DomEvent(window.event);
    if (rightButtonClicked(e) && cellIsSelected(e.target))
        args.set_cancel(true);
}
 
// And setting the event handlers for the grid
        <ClientSettings >
            <ClientEvents OnCellSelecting="cellSelecting" OnCellDeselecting="cellDeselecting"  />
            <Selecting CellSelectionMode="MultiColumn"></Selecting>
        </ClientSettings>

Thanks
/Mats
Tags
Grid
Asked by
Mats
Top achievements
Rank 1
Answers by
Mats
Top achievements
Rank 1
Share this question
or