dynamic user interface (win app)

  • Thread starter Thread starter Roy Lawson
  • Start date Start date
R

Roy Lawson

I want to enable the user to define parts of their user interface. I
am developing an application that does some accounting functions
(basicly the end user enters revenues for each account, and users will
frequently enter data in several accounts that I want visible based
upon the company).

Anyways, not that the brief description I just gave you will help, but
any ideas on how to dynamicly populate controls on a winform?? What
would be the winform equivilent of the ASP.NET repeater control? Or
am I on the wrong track?

Thanks,

-RL
 
Roy,

I use a dataset the retrieves data from a db to dynamically build controls
on a winform. You could also use XML to do it. If you want to see an
example just respond back and I will email it to you or post the code on
here.

Good Luck
 
Hi all,

I am interested like to see the example. Could you post
the code here.

Thanks

Simon
 
Hello,

Thanks for your post. As I understand, you want to dynamically add controls
to WinForms. Please correct me if there is any misunderstanding. The Form
class in WinForm includes a control collection representing a collection
of controls on the form. We just need to create a control (say, button,
etc) and then add it to Form.ControlCollection. I believe the following
articles/samples are helpful:

Form.ControlCollection Class
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformsformcontrolcollectionclasstopic.asp?frame=true

Adding a control to a form programmatically
http://www.developersdex.com/gurus/articles/62.asp

Please feel free to let me know if you have any problems or concerns.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Here is some code to create a dynamic control:
string controlType = System.Windows.Forms.Label or
System.Windows.Forms.TextBox...

Assembly assem = Assembly.GetAssembly(typeof(Form));
Type t = assem.GetType(controlType);
object obj = Activator.CreateInstance(t);
Control tb = (Control)obj;
this.Controls.Add(tb);

All of my data is stored in a db table and based on user input the app
retrieves the data to create the controls. It just loops through each row
retrieved. In a web app, I have used an XML file to create dynamic controls
using the same approach except for writing some code to extract the data
from the xml file.

I also have seen another approachs where you create component class with a
Factory Class, IControl interface, and Control Classes. I like the approach
above better because it gives you better control over creating the control.
Especially if you need to add event handlers and so on.

Hope this helps out.
 
Back
Top