Examplecode request for dynamicaly instantiating .net contro

Posted by agent_008_nl on 16-Jun-2009 08:53

Hi,

I would like to see some samplecode where a couple of .net UI controls are dynamically instantiated, including dynamically setting some properties for them  and parenting them eachother.

--
Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

www.linkedin.com/in/stefanhoutzager

All Replies

Posted by Admin on 16-Jun-2009 09:04

Can you tell us more about your use case? That's a wide area you are asking about....

You can dynamically create .NET Controls using the DYNAMIC-NEW statement. However the ABL does not allow you to dynamically set property values. Is it enough that you set the properties defined at the System.Windows.Forms.Control class (like Location and Size, Enabled and Text)? The Controls collection (child Controls) is also accessible from the Controls class.

If you need access to all properties a specific Control has to offer, you are asking about reflection which can be used for .NET Controls in the AVM as well.

Posted by jquerijero on 16-Jun-2009 09:21

Here is a dynamic way of adding treeview to the ultraWinExplorerBar (is already in the Form) when the GroupStyle is set to ControlContainer. For the most part container classes (including Form) have Controls collection where you add its child. Other collections commonly used to add UI elements are Nodes and Items.

DEFINE VARIABLE ultraExplorerBarGroup  AS Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarGroup NO-UNDO.

DEFINE VARIABLE ultraExplorerBarContainerControl AS Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarContainerControl NO-UNDO.

DEFINE VARIABLE treeView AS Infragistics.Win.UltraWinTree.UltraTree NO-UNDO

/* NAVIGATION BAR: Create the bar */

ultraExplorerBarGroup = NEW Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarGroup().          

/* Add the bar to the explorer object */

ultraWinExplorerBar:Groups:Add(ultraExplorerBarGroup). ultraExplorerBarGroup:Text = "Some Text".

/* Create the container of the child's items*/

ultraExplorerBarContainerControl = NEW Infragistics.Win.UltraWinExplorerBar.UltraExplorerBarContainerControl().

ultraWinExplorerBar:Controls:Add(ultraExplorerBarContainerControl).

/* Assign the container placeholder to the group

ultraExplorerBarGroup:Container = ultraExplorerBarContainerControl.

/* Create a control that will be shown and set Docking to Fill the placeholder */

treeView = NEW Infragistics.Win.UltraWinTree.UltraTree().

treeView:Dock = DockStyle:Fill.

treeView:Tag = "Some Private Data".

ultraExplorerBarContainerControl:Controls:Add(treeView)

/* Subscribed to event */

treeView:MouseDown:SUBSCRIBE(THIS-OBJECT:treeView_MouseDown).

Posted by agent_008_nl on 16-Jun-2009 09:31

Thanks for reacting Mike,

I would like to explore a wide area as long as I have time to learn gui for.net. I would like to create a small repository-based application. In the repository I have a table 'controls' with a unique number, the typename, a parentcontrolnumber and some properties that are used a lot like name, text etc. Futher I have a childtable 'properties' with controlnumber, propertyname, value and what is needed further.

  I would be happy with an example with f.e. a form with a button and an editor with some of their properties set dynamicilly using the reflection api. My experience with 'gui for abl' is that the possibilities were great. How would that be for a dynamic gui for.net.

Kind regards,

Stefan Houtzager

Houtzager ICT consultancy & development

www.linkedin.com/in/stefanhoutzager

Posted by Admin on 16-Jun-2009 09:42

Well, the first OE GUI for .NET Repository available was this one: http://dynamics4.net

Let me see, I'll create a tiny sample for you!

Mike

Posted by jquerijero on 16-Jun-2009 09:43

I'm not sure if it's possible to use reflection on ABL classes.

Posted by Admin on 16-Jun-2009 09:45

The PropertyGrid runs fine in ABL GUI for .NET but it won't help you when the data comes from a "repository database". It's mainly for human input...

Posted by jquerijero on 16-Jun-2009 09:49

Yeah, I caught that.

Posted by agent_008_nl on 16-Jun-2009 09:59

Thanks in advance Mike,

The first who came to mind to answer my question was you, because of your work on dynamics4.net.

Schönen Abend,

Stefan.

Posted by Admin on 16-Jun-2009 10:30

No it's not - but on the .NET portion of an ABL class inheriting from a .NET class (UserControls or Inherited Controls).

Posted by Admin on 16-Jun-2009 10:33

Stefan, attached is a simple solution that shows the use of the Reflection API in the ABL.

It contains a .p file, run-dynamic-ui.p that creates a Form, ReflectionForm. In that Form there are two methods

CreateChildControl and

SetChildControlProperty

It has some basic error handling, but I'm sure it can be improved.

The UserControl is mainly contained to test, that an ABL class inheriting from a .NET type can be used as well.

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/ReflectionSample.zip:550:0]

Posted by agent_008_nl on 17-Jun-2009 02:33

Great Mike, thanks a lot!!

This thread is closed