3

I have a listview. By default, all items have itemInvoke and single-selection enabled. But now, I would like to disable selection and itemInvoke (both event and animation) for one particular item with id "disableMe". Is there a way to do it? Or is it possible to disable the event for the whole group (not the whole listview).?

1 Answer 1

4

Answering my own question because I happened to figure it out today. Please advice if you have better solution for this issue.

In Metro Style Application, selection in ListView control can usually be triggered by Right-Click with mouse or by a small 'drag'/'swipe' with touch. To disable touch selection, you need to overwrite the MSPointerDown event handler for that particular item. To disable 'Right-Click' selection, you need to overwrite the oncontextmenu event for that particular item.

If you are creating itemTemplate in Javascript:

function listViewItemTemplate(item) {
    // data has boolean properties called 'doNotSelectMe' and 'doNotInvokeMe'
    var data = item.data._value;

    var itemElement = document.createElement('div');
    var itemElement.id = 'testElement';

    if (data.doNotSelectMe) {
        // disable mouse selection
        itemElement.oncontextmenu = function (e) { e.stopPropagation(); };
        // disable touch selection
        itemElement.addEventListener('MSPointerDown', function (e) {
                                          e.stopPropagation();
                                     });
    }

    if (data.doNotInvokeMe) {
        //disable item invoke event
        itemElement.onclick = function (e) { e.stopPropagation(); };
    }

    return {element: itemElement}

}
Sign up to request clarification or add additional context in comments.

1 Comment

So I'm selecting the template dynamically: element = document.querySelector(".inputTemplate"); and then soon thereafter rendering it to a new container: var container = document.createElement("div"); element.winControl.render(currentItem.data, container); and then later testing if the item is a certain type and doing what you wrote, worked the first time. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.