开发者

character focus on asp.net tree view

I h开发者_运维技巧ave a treeview inside a panel. The tree view has a parent and a child. The focus needs to go to the corresponding parent or child when I press any character on the keyboard. I tried to Google a solution but I couldn't find any.


You will need to use some JavaScript to achieve what you're trying.

You'll need to look at keyboard events to see which key is being pressed and then focus the correct element.


        document.onkeyup = function keyPress(e) {
        wkey = e.which ? e.which : window.event.keyCode;
        var ch = String.fromCharCode(wkey).trim();
        var chlower = ch.toLowerCase().trim();

        var foo = [];
        var fo = [];
        var k = 0;
        var lastword;
        var looping = [];
        var lastwordforkeypress;

        $('#ctl00_mainContentPlaceHolder_channelTreeView table').each(function(l, table) {
            looping[l] = $(table).text().trim();
            if (looping[l].indexOf(ch) === 0 || looping[l].indexOf(chlower) === 0) {
                lastwordforkeypress = looping[l];
            }
        });

        $('#ctl00_mainContentPlaceHolder_channelTreeView table').each(function(i, table) {
            foo[i] = $(table).text().trim();
            if (foo[i].indexOf(ch) === 0 || foo[i].indexOf(chlower) === 0) {
                fo = $('#keystroke').html().split(',');

                if (fo[k].trim() == foo[i].trim()) {                        
                    k = k + 1;
                }
                else {
                    $('#keystroke').html($('#keystroke').html() + foo[i] + ',');
                    lastword = foo[i].trim();
                    var keystroke = $('#keystroke').html()
                    if (keystroke.indexOf(ch) === 0 || keystroke.indexOf(chlower) === 0) {
                        $('table').select().css({ backgroundColor: 'white' });
                        $(table).select().css({ backgroundColor: 'orange' });
                        if (lastwordforkeypress == lastword) {
                            $('#keystroke').html('');
                            k = 0;
                        }
                        return false;
                    }
                    else {
                        $('#keystroke').html('');
                        k = 0;
                        $('#keystroke').html($('#keystroke').html() + foo[i] + ',');
                        $('table').select().css({ backgroundColor: 'white' });
                        $(table).select().css({ backgroundColor: 'orange' });
                        return false;
                    }
                }
            }
        });
    }

I achieved through Jquery. But the thing is i couldn't scroll the panel scroll bar when focus is going down on tree view. have no idea at all. help needed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜