Make Combox box selecte an item in Linux lazarus / 31-LCL ---------------------------------------------------------------------- SassyPenguin · 2021-09-26 14:56 Hi, has anyone able to pre-select an item in Combo box under Linux? The combo box won't select the item when drop down under Linux, or is there different method of select an item under linux? Sample list in Combobox "Japan" "China" "USA" "Rasia" "India" "Europ" Combobox1.ItemIndex :=  0 'should make "Japan" selected when drop down, but nothing is selected or highlighted under Linux. Work fine under Windows though. Thank you guys. ---------------------------------------------------------------------- dsiders · 2021-09-26 15:57 Quote from: jamestien on September 26, 2021, 04:56:40 pmHi, has anyone able to pre-select an item in Combo box under Linux? The combo box won't select the item when drop down under Linux, or is there different method of select an item under linux? Sample list in Combobox "Japan" "China" "USA" "Rasia" "India" "Europ" Combobox1.ItemIndex :=  0 'should make "Japan" selected when drop down, but nothing is selected or highlighted under Linux. Work fine under Windows though. Thank you guys. Some additional information about the Lazarus/LCL version and the target widgetset (GTK, GTK3, QT5) would be helpful. Most folks add that info to their forum profile to save time. ---------------------------------------------------------------------- SassyPenguin · 2021-09-26 16:26 QuoteSome additional information about the Lazarus/LCL version and the target widgetset (GTK, GTK3, QT5) would be helpful. Most folks add that info to their forum profile to save time. Sorry, I forgot to mention... Lazarus: v2.0.10 (gtk2) FPC: v3.2 Linux: Pop!Os 21.04 (64bit) Gnome: v3.38.5 ---------------------------------------------------------------------- ASerge · 2021-09-26 16:29 Quote from: jamestien on September 26, 2021, 04:56:40 pm"Rasia" "India" "Europ" Maybe Russia and Europe? ---------------------------------------------------------------------- winni · 2021-09-26 16:55 Hi! Just tested: No problems with fpc 3.2, Laz 2.0.12,  gtk2, Suse Tumbleweed Winni ---------------------------------------------------------------------- SassyPenguin · 2021-09-27 01:32 I tested with simple Combobox and the ItemIndex method works on Linux, (pre-selected appears at middle when popup), maybe I wasn't state clearly the problem. I created a Combobox as editor for the StringGrid.SelectEditor event , it should Dropdown and select the item when "GetTextEdit" event is triggered. 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.StringGrid1.GetEditText(Sender: TObject; ACol, ARow: Integer;  var Value: string);var  {$IFDEF Debug}  i: Integer;  {$ENDIF}begin  if ACol = 1 then    begin          //Tell Combobox to pre-select an item, not working on Linux.          {$IFDEF Debug}                  i := TCustomComboBox((Sender as TStringGrid).Editor).Items.Count;                i := TCustomComboBox((Sender as TStringGrid).Editor).Items.IndexOf(Value);                 TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex := i;               i := TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex;          {$ELSE}                TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex := TCustomComboBox((Sender as TStringGrid).Editor).Items.IndexOf(Value);          {$ENDIF}    end;end;            {=== Create combo box and assign it as Editor ===}procedure TForm1.StringGrid1.SelectEditor(Sender: TObject; aCol,  aRow: Integer; var Editor: TWinControl);begin  case Acol of    1: //Name     begin        Editor := (Sender as TStringGrid).EditorByStyle(cbsPickList) ;        TCustomComboBox(Editor).Items.Assign(PickList_Name);          TCustomComboBox(Editor).AutoComplete := True;                   {$IFDEF Windows}            TCustomComboBox(Editor).AutoDropDown := TRUE;          {$ENDIF}     end;    5:  //Subtotal      Editor := nil ; //readonly  end; ---------------------------------------------------------------------- SassyPenguin · 2021-09-27 02:10 Sample program attached to reproduce. The combobox list doesn't highlight (selected state) on Linux. 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.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl);begin     begin          {Method #1 --- use existing Combobox ---}                  Combobox1.BoundsRect := (Sender as TStringGrid).CellRect(aCol,aRow);                  Editor := ComboBox1;          {Method #2 --- create dynamically ---}                {Editor := (Sender as TStringGrid).EditorByStyle(cbsPickList) ;                  TPickListCellEditor(Editor).Items.Assign(FieldList);                  TPickListCellEditor(Editor).AutoDropDown := True;                  TPickListCellEditor(Editor).AutoComplete := True;}     end;end; procedure TForm1.FormCreate(Sender: TObject);begin  FieldList := TStringList.Create;  FieldList.Add('Classes');  FieldList.Add('SysUtils');  FieldList.Add('Forms');  FieldList.Add('Controls');  FieldList.Add('Graphics');  FieldList.Add('Dialogs');  FieldList.Add('Grids');  ComboBox1.Items.Assign(FieldList);   StringGrid1.InsertRowWithValues(1 ,['','Classes','SysUtils','Forms','Dialogs']) ;end; procedure TForm1.FormDestroy(Sender: TObject);begin   FreeAndNil(FieldList);end; procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer; var Value: string);begin   {Method #1 --- use existing Combobox ---}         Combobox1.ItemIndex := Combobox1.Items.IndexOf(Value);   {Method #2 --- create dynamically ---}           //TPickListCellEditor((Sender as TStringGrid).Editor).ItemIndex := TPickListCellEditor((Sender as TStringGrid).Editor).Items.IndexOf(Value);end; ---------------------------------------------------------------------- Handoko · 2021-09-27 03:08 When posting code, please use code tag: https://wiki.freepascal.org/Forum#Use_code_tags It will be much helpful if you can provide the compile-able source code so others can test it on their computers easily. If don't know how to do it: Lazarus main menu > Project > Publish Project Alternatively, you can: Create a new folder, copy and paste all the necessary files (including the data file) except: the binary (exe file), *.bak, lib and backup folders. Compress the folder and send the zip to the forum. ---------------------------------------------------------------------- SassyPenguin · 2021-09-27 03:54 Quote from: Handoko on September 27, 2021, 05:08:52 amWhen posting code, please use code tag: https://wiki.freepascal.org/Forum#Use_code_tags Thank you for pointing this out hehe, I'm new to this forum. Post updated.