Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Okay, I want to add multiple user controls into a flow panel at one time without the UI freezing, I've tried adding the controls from a Background Worker but get an error about how it cannot be added because it can't change parent control or something like that, any help would be appreciated.
Posted

1 solution

You are going to have to create a delegate to add the controls for you, something like this:

** assuming your flow control is called 'flow'
VB
private delegate sub delAddControl(ctrl as Control)
private sub AddControl(ctrl as Control)
    if (flow.InvokeRequired) then
        dim d as new delAddControl(AddressOf AddControl)
        me.Invoke(d, ctrl)
    else
        flow.Controls.Add(ctrl)
    end if
end sub


I have written this code 100 times in C# but my vb is a little rusty so im sure this wont compile but you should be able to see what im doing and get yours working from that.


**** EDIT *****
Oh Yea, then you can just call AddControl from your BackgroundWorker and the controls will get added to your UI without locking it up because the heavy lifting is being done in the BackgroundWorker.
 
Share this answer
 
v2
Comments
Kieran Crown 20-Dec-12 6:29am    
Thank you very much, worked just as I wanted it to :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900