Hi, my question is quite in the title. How can i focus a specific control when onPageChange event is fired ?
i.e I have a 2 tab pagecontrol on each i have one or more TEdit and i want my focus set to first one when i navigate between pages (clicking on tab)
Hi,
Have you tried to OnChangePage event?
Oh yes, I tried this (bureau is the tPageControl)
case Bureau.ActivePageIndex of
0 : Edit1.SetFocus;
1 : Edit2.SetFocus;
2 : Edit3.SetFocus;
else begin
TChild(Ft).StartFocus; // ft is a TForm (actually TChild
Memo1.Lines.Add('StartFocus');
end;
end;
{adding a TForm class TChild like this
procedure TMain.AddPageClick(Sender: TObject);
var F : TChild;
ATabItem : TTMSFMXPageControlPage;
begin
if Assigned(ft) then exit;
F:=TChild.Create(Self);
Ft:=F;
ATabItem:=Bureau.AddPage(Format('Tab %d',[Bureau.Pages.Count]));
ATabItem.TabSet.CanFocus:=False;
ATabItem.TabSet.AllowFocus:=False;
ATabItem.Container.AddObject(F.Layout1);
end;
}
But without success, I check also that tabsets canfocus and allowfocus properties are false
To be noted the quasi same code works with TTabControl
{//if Bureau is a TTabControl
Found a way, I use the OnAfterDrawTabBackground event to change the focus
procedure TMain.BureauPageAfterDrawTabBackground(Sender: TObject;
AGraphics: TTMSFMXGraphics; ATabIndex: Integer; ARect: TRectF;
AState: TTMSFMXTabSetTabState);
begin
if (ATabIndex= BureauPage.ActivePageIndex)
then begin
BureauPageChangeIndex(ATabIndex);
end;
end;
procedure TMain.BureauPageChangeIndex(index: integer);
begin
case Index of
-1 : ;
0 : Edit1.SetFocus;
1 : Edit2.SetFocus;
2 : Edit3.SetFocus;
else begin
TChild(FP).StartFocus;
DebugMemo.Lines.Add('StartFocus');
end;
end;
end;
But IMHO it's an unatural way do do the trick !
Is this not focusing control a bug or not ? that is the question
We're still investigating. It's unclear exactly what happens. Alternatively, you could set a FFocusedControl private variable and start a timer instead, which then focusses the control. Or set the TabStop property to False on each page.
Oh yes i think about this solution (found in a forum somewhere) but this one seem for my eyes as unnatural as my OnAfterDrawTabBackground solution
as far as i check in my test program all tabstop page properties are False
Hi,
It's less unnatural then using OnAfterDrawTabBackground. It could potentially be an FMX bug. We have used timers before for focusing controls in other applications, or event components such as inplace editors in the treeview, simply to workaround the issue.
Hello, sorry for this delay due to seakness
Sorry I don't adhere this FMX bug theory, except if by this you speak about style.
Why ?
1- using the supplied ttabcontrol no problem to focus the wanted control
2- using OnAfterDrawTabBackground works great yes but i had to add some trick because with the code supplied i was enable to focus on a next control (ie a second Tedit). It is as if changing the focus of TEdit1 to TEdit2 (on the same page) fire the event !
But perhaps i miss a property ?
Hi,
We have further investigate this here and have applied a fix. The next version will address this.