你如何响应一次在ListView控件选择范围用户? [英] How do you respond ONCE to a user selecting a range in a ListView control?

查看:144
本文介绍了你如何响应一次在ListView控件选择范围用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想处理哪些项目在列表框中选择(通过更新有关的选择什么样的信息),用户不断变化的,但如果你选择一个范围(使用Shift +选择),它实际上触发一个单独的ItemSelectionChanged事件一次,如果你选择的100个项目中选择/取消选择,即每个项目,你会得到100个事件,并在第一时间调用该事件处理程序的,好像还没有办法知道,有更多的惊喜的方式。

I'm trying to handle the user changing which items are selected in a listbox (by updating information about what's selected), but if you select a range (using shift+select), it actually fires a separate 'ItemSelectionChanged' event once for EACH item that was selected/deselected, i.e. if you selected 100 items, you get 100 events, and the first time the event handler's called, it seems to have no way of knowing that there's more to come.

有没有办法不直到选择的过程中应对/取消项目完成?

Is there a way to not respond until the process of selecting/deselecting items is complete?

推荐答案

有没有SelectedItemsChanged事件,我猜你的意思的SelectedIndexChanged。你可以做的是利用Control.BeginInvoke()方法。委托目标开始运行时UI线程进入闲置状态再次,所有的事件都被解雇了。使它看起来是这样的:

There is no SelectedItemsChanged event, I'm guessing you mean SelectedIndexChanged. What you can do is leverage the Control.BeginInvoke() method. The delegate target starts running when the UI thread goes idle again, after all the events have been fired. Make it look like this:

    bool listUpdated = false;

    private void listView1_SelectedIndexChanged(object sender, EventArgs e) {
        if (!listUpdated) {
            this.BeginInvoke(new MethodInvoker(updateList));
            listUpdated = true;
        }
    }

    private void updateList() {
        listUpdated = false;
        // etc...
    }

这篇关于你如何响应一次在ListView控件选择范围用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆