[Gambas-user] Modify a control in another form

Fabien Bodard gambas.fr at ...626...
Mon Sep 24 17:53:13 CEST 2012


2012/9/23 richard <rterry at ...1823...>:
> On 23/09/12 08:44, richard wrote:
>> On 23/09/12 08:31, Keith Clark wrote:
>>> On 12-09-22 06:23 PM, richard wrote:
>>>> On 23/09/12 08:03, Keith Clark wrote:
>>>>> How do I modify settings of a control on another form?  Let's say that I
>>>>> want to be able to control the number of rows and columns of a grid
>>>>> view, gvSampleGrid, on form, fGameGrid from form, fGameSetup.
>>>>>
>>>>> Would it not be fGameGrid.gvSampleGrid.rows.count=10?
>>>>>
>>>>> I am working with the book A beginner's Guide to Gambas but find it
>>>>> confusing on the basics.
>>>>>
>>>>> Thanks.
>>>>> If you have set your projects options to make your controls public you
>>>>> can address any control on anther form with the correct syntax
>>>>>
>>>>> What error message to you get when you run your code?
>>>>>
>>>>> richard
>>>>>
>>>>>
>>> That is exactly what I didn't do!  Set the controls to public.  Done now
>>> and it works fine.  Thanks!
>>>
>>> Keith
>>>
>>>
>> Also remember you can pass anything from form to form even forms, or
>> pass forms to code modules. Also you can declare a form
>>
>> For example if  you used alot of say columnviews all over a large
>> project and did the same sort of thing to the columnview in all the
>> forms, simple example, allow the user to change the font of a columnview
>> and save it to a settings file via a pop-up menu over the columnview,
>> you could have a general module in your project, and pass the columnview
>> to that module, do whatever on it you wanted. Then you have a single few
>> lines of code you re-use in dozens and dozens of situations.
>>
>> e.g I have a module I call modUtil and puts lots of stuff in it which is
>> used all over the place
>>
>> Public Sub Columnview_SetFont(cvw As Columnview, Settings_Section As String)
>> '----------------------------------------------------------------------------------------------------------------
>>      'Attempts to change the font of a columnview and save to settings
>> '---------------------------------------------------------------------------------------------------------------
>>
>>      Dialog.font = cvw.font
>>      If Dialog.SelectFont() Then Return
>>      cvw.font = Dialog.Font
>>      Settings[Settings_Section & "/" & cvw.name & ".font"] =
>> cvw.Font.ToString()
>>
>> End
>>
>>
>>
> As an addendum you will have to in this case load your previously saved
> font value from your settings file.
> I always have  a Private sub Settings_Load() in each form and a Public
> Sub Settings_Save()
>
> e.g
>
> Private sub Settings_Load()
>
>    Try cvwItemsBilled.Font =
> Font[Settings["Billing_RecordVisit/cvwItemsBilled.font"]]
>
> end sub
>
> Note the Settings_Save is Public, as then, if I have multiple sub-forms
> on another form which is closed, the the 'Parent' form can call all the
> Settings_Save subroutines in all its embedded forms when it closes.
>
> Regards
>
> richard
>
>
>
>
> ------------------------------------------------------------------------------
> How fast is your code?
> 3 out of 4 devs don\\\'t know how their code performs in production.
> Find out how slow your code is with AppDynamics Lite.
> http://ad.doubleclick.net/clk;262219672;13503038;z?
> http://info.appdynamics.com/FreeJavaPerformanceDownload.html
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user

I think the good way is this one :

Never make your form public !!!

Prefers that ... In the gridviewform :


Public Function GetGrid() as GridView

Return MyGridView

End



THen you can use that in another form to manage the grid :


Form1.GetGrid().Rows.Count...


Well if you just need to modify the number of row you can do that too

In the gridview form :

Public Sub SetGridRows(iCount as Integer)

  MyGridView.Rows.Count = iCount

End


Setting Forms public have a cost in Time,Memory and make the code less clearer

-- 
Fabien Bodard




More information about the User mailing list