Raise event in custom component

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Raise event in custom component

Post by bill-lancaster »

I have a custom component containing a gridview which is populated and the first row selected in the _new() procedure.

Clicking on a row in the gridview raises an event ('ChangeCat' in my project).

How to raise this event as soon as the control is loaded (i.e. with no further user action)?
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Raise event in custom component

Post by BruceSteers »

Have you tried setting the index in the _Show event not _new ?
Or your form_open
The control has not yet initialised in _new
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Raise event in custom component

Post by bill-lancaster »

Thanks Bruce,
This control draws 2 gridviews , a buttonbox etc all inside a Frame (hFrame) on the parent form so hFrame doesn't have a _Open or _Show event.
Have just tried hFrame_Activate() and hFrame_GotFocus() but these events aren't triggered.
Hope this makes sense.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Raise event in custom component

Post by cogier »

Try GridView1_Arrange(). This is triggered when the GridView has finished arranging its contents. NOTE that if you change anything or resize the Form this will be triggered.

Can't you simply call ChangeCat as the last command in _new()?
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Raise event in custom component

Post by bill-lancaster »

Thanks cogier, GridView1_Arrange() does the job.
'Raise ChangeCat' in _new() doesn't work.
Thanks again
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Raise event in custom component

Post by BruceSteers »

can you not just run the event command from the main form on load without requiring the initial trigger?

Ie..
Public Sub Form_Open()

  MyControl_ChangeCat()

End
just make sure the ChangeCat() sub uses direct links to the Control not the "Last" keyword

or in the Form_Open() explicitly set the gridview row
Public Sub Form_Open()

  MyControl.Grid1.Select(0)

End
(or however you would set the grid item)
Last edited by BruceSteers on Sunday 28th August 2022 7:59pm, edited 3 times in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1521
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Raise event in custom component

Post by BruceSteers »

also did you try the special method _ready() ?
If at first you don't succeed , try doing something differently.
BruceS
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

Re: Raise event in custom component

Post by bill-lancaster »

Thanks Bruce,
Putting the raise event in _Ready() doesn't work.
I've been running the event from the parent form but was trying to skip this step.
In the _new() sub, the table is filled with data and the first line is selected. At the moment gridview_Arrange() works fine.
Thanks again
Post Reply