Recent

Author Topic: Make Combox box selecte an item in Linux  (Read 2729 times)

SassyPenguin

  • New Member
  • *
  • Posts: 49
Make Combox box selecte an item in Linux
« on: September 26, 2021, 04:56:40 pm »
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.
« Last Edit: September 26, 2021, 05:01:20 pm by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

dsiders

  • Hero Member
  • *****
  • Posts: 1052
Re: Make Combox box selecte an item in Linux
« Reply #1 on: September 26, 2021, 05:57:58 pm »
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.

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.
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

SassyPenguin

  • New Member
  • *
  • Posts: 49
Re: Make Combox box selecte an item in Linux
« Reply #2 on: September 26, 2021, 06:26:21 pm »
Quote
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.

Sorry, I forgot to mention...

Lazarus: v2.0.10 (gtk2)
FPC: v3.2
Linux: Pop!Os 21.04 (64bit)
Gnome: v3.38.5
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

ASerge

  • Hero Member
  • *****
  • Posts: 2222
Re: Make Combox box selecte an item in Linux
« Reply #3 on: September 26, 2021, 06:29:22 pm »
"Rasia"
"India"
"Europ"
Maybe Russia and Europe?

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Make Combox box selecte an item in Linux
« Reply #4 on: September 26, 2021, 06:55:27 pm »
Hi!

Just tested: No problems with

fpc 3.2, Laz 2.0.12,  gtk2, Suse Tumbleweed

Winni

SassyPenguin

  • New Member
  • *
  • Posts: 49
Re: Make Combox box selecte an item in Linux
« Reply #5 on: September 27, 2021, 03:32:10 am »
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][+][-]
  1. procedure TForm1.StringGrid1.GetEditText(Sender: TObject; ACol, ARow: Integer;  var Value: string);
  2. var
  3.   {$IFDEF Debug}
  4.   i: Integer;
  5.   {$ENDIF}
  6. begin
  7.   if ACol = 1 then
  8.     begin
  9.           //Tell Combobox to pre-select an item, not working on Linux.
  10.           {$IFDEF Debug}
  11.                   i := TCustomComboBox((Sender as TStringGrid).Editor).Items.Count;
  12.                   i := TCustomComboBox((Sender as TStringGrid).Editor).Items.IndexOf(Value);
  13.                  TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex := i;
  14.                  i := TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex;
  15.           {$ELSE}
  16.                 TCustomComboBox((Sender as TStringGrid).Editor).ItemIndex := TCustomComboBox((Sender as TStringGrid).Editor).Items.IndexOf(Value);
  17.           {$ENDIF}
  18.     end;
  19. end;          
  20.  
  21. {=== Create combo box and assign it as Editor ===}
  22. procedure TForm1.StringGrid1.SelectEditor(Sender: TObject; aCol,  aRow: Integer; var Editor: TWinControl);
  23. begin
  24.   case Acol of
  25.     1: //Name
  26.      begin
  27.           Editor := (Sender as TStringGrid).EditorByStyle(cbsPickList) ;
  28.           TCustomComboBox(Editor).Items.Assign(PickList_Name);
  29.           TCustomComboBox(Editor).AutoComplete := True;
  30.          
  31.           {$IFDEF Windows}
  32.             TCustomComboBox(Editor).AutoDropDown := TRUE;
  33.           {$ENDIF}
  34.      end;
  35.     5:  //Subtotal
  36.       Editor := nil ; //readonly
  37.   end;
« Last Edit: September 27, 2021, 05:52:38 am by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

SassyPenguin

  • New Member
  • *
  • Posts: 49
Re: Make Combox box selecte an item in Linux
« Reply #6 on: September 27, 2021, 04:10:21 am »
Sample program attached to reproduce. The combobox list doesn't highlight (selected state) on Linux.


Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1SelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl);
  2. begin
  3.      begin
  4.           {Method #1 --- use existing Combobox ---}
  5.                   Combobox1.BoundsRect := (Sender as TStringGrid).CellRect(aCol,aRow);
  6.                   Editor := ComboBox1;
  7.           {Method #2 --- create dynamically ---}
  8.                   {Editor := (Sender as TStringGrid).EditorByStyle(cbsPickList) ;
  9.                   TPickListCellEditor(Editor).Items.Assign(FieldList);
  10.                   TPickListCellEditor(Editor).AutoDropDown := True;
  11.                   TPickListCellEditor(Editor).AutoComplete := True;}
  12.      end;
  13. end;
  14.  
  15. procedure TForm1.FormCreate(Sender: TObject);
  16. begin
  17.   FieldList := TStringList.Create;
  18.   FieldList.Add('Classes');
  19.   FieldList.Add('SysUtils');
  20.   FieldList.Add('Forms');
  21.   FieldList.Add('Controls');
  22.   FieldList.Add('Graphics');
  23.   FieldList.Add('Dialogs');
  24.   FieldList.Add('Grids');
  25.   ComboBox1.Items.Assign(FieldList);
  26.  
  27.   StringGrid1.InsertRowWithValues(1,['','Classes','SysUtils','Forms','Dialogs']) ;
  28. end;
  29.  
  30. procedure TForm1.FormDestroy(Sender: TObject);
  31. begin
  32.    FreeAndNil(FieldList);
  33. end;
  34.  
  35. procedure TForm1.StringGrid1GetEditText(Sender: TObject; ACol, ARow: Integer; var Value: string);
  36. begin
  37.    {Method #1 --- use existing Combobox ---}
  38.            Combobox1.ItemIndex := Combobox1.Items.IndexOf(Value);
  39.    {Method #2 --- create dynamically ---}
  40.            //TPickListCellEditor((Sender as TStringGrid).Editor).ItemIndex := TPickListCellEditor((Sender as TStringGrid).Editor).Items.IndexOf(Value);
  41. end;
  42.  
« Last Edit: September 27, 2021, 05:58:33 am by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

Handoko

  • Hero Member
  • *****
  • Posts: 5130
  • My goal: build my own game engine using Lazarus
Re: Make Combox box selecte an item in Linux
« Reply #7 on: September 27, 2021, 05:08:52 am »
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

  • New Member
  • *
  • Posts: 49
Re: Make Combox box selecte an item in Linux
« Reply #8 on: September 27, 2021, 05:54:06 am »
When 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.
« Last Edit: September 27, 2021, 05:59:44 am by jamestien »
Lazarus 2.2.4 (Win11, Manjaro KDE, CachyOS KDE, Linux Mint)

 

TinyPortal © 2005-2018