[SOLVED] Make ComboBox DroppedDown in manually created Form lazarus / 21-General ---------------------------------------------------------------------- cris75 · 2022-10-26 10:28 Hi, I have a manually created Form which contains among other items a ComboBox; here it is: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function TForm1.SelectInput(pWidth, aTop, aLeft, aWidth: Integer;  const aCaption, aDescription, s: string; out ReturnString: string): boolean;var  cFrm    : TForm;  aLabel  : TLabel;  aCancel : TBitBtn;  aOk     : TBitBtn;  aCBox   : TComboBox;begin  Result:= FALSE;  ReturnString:= '';  cFrm                          := TForm.Create(nil);  cFrm.BorderIcons              := cFrm.BorderIcons - [biMinimize, biMaximize];  cFrm.Constraints.MaxHeight    := 110;  cFrm.Constraints.MaxWidth     := aWidth;  cFrm.Constraints.MinHeight  := 110;  cFrm.Constraints.MinWidth     := aWidth;  cFrm.Top                    := aTop;  cFrm.Left                     := aLeft + (pWidth - aWidth) div 2;  cFrm.Width                    := aWidth;  cFrm.Height                   := 110;  cFrm.Constraints.MinWidth     := 200;  cFrm.Caption                  := aCaption;  aLabel                      := TLabel.Create(cFrm);  aLabel.Parent                 := cFrm;  aLabel.Top                    := 10;  aLabel.Left                 := 20;  aLabel.Caption                := aDescription;  aLabel.AutoSize               := True;  aCBox                         := TComboBox.Create(cFrm);  aCBox.ItemIndex               := -1;  aCBox.Parent                  := cFrm;  aCBox.TextHint                := '';  aCBox.Top                     := 30;  aCBox.Left                  := 20;  aCBox.Width                   := aWidth - 40;  aCBox.Items.Delimiter         := ',';  aCBox.Items.SkipLastLineBreak := TRUE;  aCBox.Items.DelimitedText     := AnsiProperCase(s, [',']);  aCBox.Sorted                  := TRUE;  aCancel                       := TBitBtn.Create(cFrm);  aCancel.Parent                := cFrm;  aCancel.Top                   := cFrm.Height - (aCancel.Height+12);  aCancel.Kind                  := bkCancel;  aCancel.Left                := (aWidth - 160) div 2;  aOk                           := TBitBtn.Create(cFrm);  aOk.Parent                    := cFrm;  aOk.Top                       := cFrm.Height - (aOK.Height+12);  aOk.Kind                    := bkOK;  aOk.Left                      := aCancel.Left + 85;   if not(cFrm.ShowModal = mrCancel) and (aCBox.ItemIndex <> -1) then begin    ReturnString:= aCBox.Text;    Result:= TRUE;  end;   cFrm.Free;end;  is it possible have the CBox "auto-expanded" when Form is shown ? I'd like to have items shown but no one selected (index -1). I saw that there is DroppedDown property but can't do it work, is it a focus related problem in my case or what, and in that case how should I implement it, any hint? Btw, items in the ComboBox are always populated in my tests with at least a couple of elements. Thanks ---------------------------------------------------------------------- Zvoni · 2022-10-26 13:34 Since you're on windows: http://www.delphicorner.f9.co.uk/articles/wapi10.htm No idea if "natively" possible ---------------------------------------------------------------------- howardpc · 2022-10-26 13:43 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.cFormActivate(Sender: TObject);var  frm: TForm absolute Sender;  c: TComponent;  cbox: TComboBox absolute c;begin  if not Sender.InheritsFrom(TCustomForm) then Exit;  for c in frm do    if c.Name = 'CBox' then begin      cbox.DroppedDown := True;      Break;  end;end; procedure TForm1.cFormShow(Sender: TObject);var  frm: TForm absolute Sender;  c: TComponent;  cbox: TComboBox absolute c;begin  if not Sender.InheritsFrom(TCustomForm) then Exit;  for c in frm do    if c.Name = 'CBox' then    begin      cbox.Items.CommaText := AnsiProperCase(cbox.Items.CommaText, [',']);      cbox.Sorted          := True;      Break;    end;end; function TForm1.SelectInput(pWidth, aTop, aLeft, aWidth: Integer; const aCaption, aDescription, aItemsCommaText: String;                            out ReturnString: String): Boolean;var  cFrm    : TForm;  aLabel  : TLabel;  aCancel : TBitBtn;  aOk     : TBitBtn;  aCBox   : TComboBox;begin  Result:= False;  ReturnString:= '';  try    cFrm                          := TForm.CreateNew(Nil);    cFrm.BorderIcons              := cFrm.BorderIcons - [biMinimize, biMaximize];    cFrm.Constraints.MaxHeight    := 110;    cFrm.Constraints.MaxWidth   := aWidth;    cFrm.Constraints.MinHeight    := 110;    cFrm.SetInitialBounds(aLeft + (pWidth - aWidth) div 2, aTop, aWidth, 110);    cFrm.Constraints.MinWidth     := 200;    cFrm.Caption                := aCaption;    cFrm.OnShow                   := @cFormShow;    cFrm.OnActivate               := @cFormActivate;     aLabel                      := TLabel.Create(cFrm);    aLabel.Top                    := 10;    aLabel.Left                   := 20;    aLabel.Caption              := aDescription;    aLabel.AutoSize               := True;  aLabel.Parent                 := cFrm;     aCBox                       := TComboBox.Create(cFrm);    aCBox.Name                    := 'CBox';    aCBox.ItemIndex               := -1;    aCBox.TextHint              := '';    aCBox.Top                     := 30;    aCBox.Left                    := 20;    aCBox.Width                   := aWidth - 40;    aCBox.Items.Delimiter         := ',';    aCBox.Items.StrictDelimiter   := True;    aCBox.Items.SkipLastLineBreak := True;    aCBox.Items.CommaText       := aItemsCommaText;    aCBox.Parent                  := cFrm;     aCancel                       := TBitBtn.Create(cFrm);    aCancel.Top                 := cFrm.Height - (aCancel.Height+12);    aCancel.Kind                  := bkCancel;    aCancel.Left                  := (aWidth - 160) div 2;    aCancel.Parent                := cFrm;     aOk                           := TBitBtn.Create(cFrm);    aOk.Top                     := cFrm.Height - (aOK.Height+12);    aOk.Kind                    := bkOK;    aOk.Left                      := aCancel.Left + 85;    aOk.Parent                    := cFrm;     if (cFrm.ShowModal <> mrCancel) and (aCBox.ItemIndex <> -1) then begin      ReturnString:= aCBox.Text;      Result:= True;    end;  finally    cFrm.Free;  end;end; ---------------------------------------------------------------------- cris75 · 2022-10-27 11:03 Hi @howardpc: your solution is the "fair copy" of the confused one I was thinking about after I asked for help (actually I wasn't so confident I was able to implement it..) Reading your code now it seems so simple.. and does exactly what I want, thanks a lot! Maybe a silly question, but I ask the same to learn from the experts: wasn't is sufficent the FormShow event and put also DroppedDown:= True there? @Zvoni: also the link you provided is useful for my for knowledge, thank you! ---------------------------------------------------------------------- howardpc · 2022-10-27 17:55 I am no expert, but it is when the form becomes active that your combobox receives focus (since it is the first control in your form's tab order). I believe setting the DroppedDown property has no effect if the combo is not focussed. I may be wrong, you can try putting it in OnShow and see if it works as you want in that event handler. ---------------------------------------------------------------------- Zvoni · 2022-10-27 18:40 Quote from: howardpc on October 27, 2022, 07:55:48 pmI am no expert, but it is when the form becomes active that your combobox receives focus (since it is the first control in your form's tab order). I believe setting the DroppedDown property has no effect if the combo is not focussed. I may be wrong, you can try putting it in OnShow and see if it works as you want in that event handler. Your point? Just SetFocus to the Combobox, if it‘s not the first control in Taborder ---------------------------------------------------------------------- howardpc · 2022-10-27 23:46 The point is that you cannot set the focus to anything until after the moment of form activation.