C#从另一个线程更新列表视图(调用)

C#从另一个线程更新列表视图(调用)

问题描述:

我被困了几天.

我想向列表视图添加一些项目.
显然不是来自gui线程.

我尝试了几种调用方法,但由于列表视图嵌套在多个表布局面板中而感到困难.

所以我用了:

I''ve been stuck for a couple of days.

I want to add some items to a listview.
Obviously not from the gui thread.

I''ve tried several ways of invoking but found it hard since my listview is nested in several tablelayout panels.

So I used:

public Control FindControl(Control container, string name)
        {
            if (container.Name == name)
                return container;
            foreach (Control ctrl in container.Controls)
            {

                Control foundCtrl = FindControl(ctrl, name);
                if (foundCtrl != null)
                {
                    return foundCtrl;
                }
                break;
           }

            return null;
       }



找到控件后,我将被调用添加它,但是这没有结果,或者它告诉我无法编辑尚未创建的句柄(因此它在错误的线程上).

无论如何,我一直在寻找一些适当的示例,其中包含嵌套在表格布局面板中的控件,尽管我找不到任何好的示例.

任何人都可以抬起头来,因为这使我发疯.
可悲的是,我无法真正删除表格布局,这会使它简单得多.
虽然我已经接近我所在的位置.

只是希望有人能为我提供解决方案!



After the control has been found I would of invoked to add it, but this gave either no result, or it would tell me that I cannot edit a handle that has not been created (So it would of been on the wrong thread).

Anyway, I''ve been looking for some proper examples with contains controls being nested inside the tablelayout panels, although I failed to find any good ones.

Could anyone give me a heads up as this is driving me crazy.
Sadly I can''t really remove the tablelayouts, that would make it a lot simpler.
Though I''m getting near the point where I am.

Just hope some one can help me with a solution!

cheers!

将所有访问gui组件的代码移动到gui线程,使用以下参数将所需数据作为参数传递: Control.Invoke方法(代理,对象[]) [
Move all code that accesses gui components to the gui thread, passing the required data as an argument using:
Control.Invoke Method (Delegate, Object[])[^]

Regards
Espen Harlinn