TOPIC: Adding controls dynamically
#805
Adding controls dynamically 3 Years, 5 Months ago
Hello,

I am trying to do a controller (Record or Access - what is the best for this purpose) wich is composed of a 'main form' (based on "Table1" and some "Tabs" that they are derived from registers of a table would second ("Table2").

1.In the main form I'll have a "ChooseList" that when will be modified, depending on the new value, it will present a "RadioButtons". For this, do it has as to mount and to show the controls (Radio) dinamicamente or is better to use "Visible/Invisible" method ?

2. To mount the "Tabs", I will make a selection of "Table2" that has a register equivalent in the "Table1". Example:

Table1 -> id = 1 (key), nome = "Ricardo"

Table2 -> id = 1(key - Table1 index), tipo = "OF", codigo = 100
id = 1, tipo "Email", codigo = 2

So, the presented window would show the main form, fields "id" and "nome" and mount the tabs dynamically, been:
"Tab1" -> text = "OF", field codigo - the control would be RECORD... is there better choice ??? Form ???
"Tab2" -> text = "Email", field codigo

Is there a way to do this dynamically ?

I hope have been clearly.

Thanks

Ricardo

ps.: sorry by my English
 
 
Last Edit: 2009/09/24 21:07 By sunadmin.
 
#806
Re:Adding controls dynamically 3 Years, 5 Months ago
You can use SetVisible(true/false) to make controls visible or invisible dynamically.

You can make tabs generated dynamically by using the ChangeControl method of Controller class inside the NewValue(value, source) method of your controller. Give a look in the User's Manual, at:

"Cookbook -> Determining the Source of Messages"

Here is a simple example:

Code:

Controller
{
Controls:
(Vert
(Horz
(Static 'Hello' name: 'st1')
(Static 'World' name: 'st2')
)
(Field)
(Field)
(Field)
(Button 'Change Control!')
)
On_Change_Control()
{
.ChangeControl(#(Tabs (Static 'this is one'  Tab: 'One') #(Editor, Tab: 'Editor')))
}
}



P.S.: I think that by 'registers' you wanted to say 'fields', and by 'mount' you wanted to say 'create', right?
 
 
Mauro
 
#807
Re:Adding controls dynamically 3 Years, 5 Months ago
Hi Mauro,

Thanks for reply...

Yes 'registers' is the return of the query = "fields"... and 'mount' is 'create'... :P

Your example is very useful, but I'd like to add the "Tabs" without replace the fields Controls...

The resultant Window will is composed by the

Code:

Controls:
        (Vert
            (Horz
                (Static 'Hello' name: 'st1')
                (Static 'World' name: 'st2')
                )
            (Field)
            (Field)
            (Field)
            (Button 'Change Control!')
            )



and the tabs under that...

Thanks in advance

Ricardo
 
 
#808
Re:Adding controls dynamically 3 Years, 5 Months ago
You can simply do something like this:

Code:

Controller
{
Controls:
(Vert
(Horz
(Static 'Hello' name: 'st1')
(Static 'World' name: 'st2')
)
(Field)
(Field)
(Field)
(Button 'Change Control!')
(Tabs (Static 'this is one'  Tab: 'One') (Editor, Tab: 'Editor'))
)

On_Change_Control()
{
.ChangeControl(
#(Vert
(Horz
(Static 'Hello' name: 'st1')
(Static 'World' name: 'st2')
)
(Field)
(Field)
(Field)
(Button 'Change Control!')
(Tabs
(Static 'I have changed the content'  Tab: 'One')
(Static 'dynamically!' Tab: 'Two')
)
)
)
}
}

 
 
Mauro
 
#809
Re:Adding controls dynamically 3 Years, 5 Months ago
Hi Mauro,

Sorry, in my first post I was not clearly...

For the first charge of the Controller, your code will run properly, because the "TabsControl" will show two Tabs (fixed - for my control) with controls of other tables ("Table3" and "Table4")... but the user can add information, which will add lines to "Table2", so the Window should show a new tab, based on the information of query from "Table2" which the user added "on-line"...

That is something like "Refresh" the Window, adding a tab with information that user added, without closing the Window.

Is there a way to do this ?

Thanks

Ricardo
 
 
#810
Re:Adding controls dynamically 3 Years, 5 Months ago
If I have understood well (sorry but your english is very difficult to understand :p), you would want to create new tabs dynamically, based on the data in tables that the user can change on the fly. In this case you should intercept the changes in your controls, and call the .ChangeControl method, as in the previous example.
There are methods to intercept a control edited by the user, as the NewValue() method I mentioned before. But maybe not all the controls send this message to the parent control, then you should always check in the stdlib code.
Maybe you should check the TabControl too (that is different from TabsControl) that should be more flexible (but more troublesome to use).
If this were too difficult for you, maybe it's better to reconsider the problem and think at a simpler design of your project.
Sorry if I can't be of more help.
 
 
Mauro