Jump to content
kaarigar

TListBox - grouping of items and horizontal scroll bar

Recommended Posts

I am using TListBox to present text strings. However I am not able to find how to group the items shown in the TListBox at run time. I have set the GroupingKind property to  Grouped but I can't find any methods to group items.

 

And also how to have the horizontal scrolling? I am setting the TListBox.ShowScrollBars to true but that has no effect.

 

I am using latest Delphi 11.3 with the patch applied and the target platform is Andoid + Windows.  Thank you!

Share this post


Link to post

@kaarigar

 

you can try some like this:  FIXED

implementation

{$R *.fmx}

procedure TForm1.Btn_Create_ItemsClick(Sender: TObject);
const
  LHeaders: array [0 .. 2] of string = ('Header1', 'Header2', 'Header3');
var
  LBGHeader      : TListBoxGroupHeader;
  LBGHeaderHeight: single;
  LBItem         : TListBoxItem;
  LBItemHeight   : single;
  LItemHeight    : single;
  LHowManyItems  : integer;
begin
  // reset all default values...
  ListBox1.Clear;
  ListBox1.ItemHeight := 0;
  ListBox1.ListStyle  := TListStyle.Vertical;
  ListBox1.Columns    := 1;
  //
  LBGHeaderHeight := 19; // default values
  LBItemHeight    := 19;
  LHowManyItems   := 1;
  //
  for var i: integer := 0 to high(LHeaders) do // if headers with distinct height, then needs some calc...
    begin
      LBGHeader      := TListBoxGroupHeader.Create(Self);
      LBGHeader.Text := LHeaders[i];
      ListBox1.AddObject(LBGHeader);
      LBGHeaderHeight := LBGHeader.Height; // here you can verify if a Header is > than before
      //
      LHowManyItems := Trunc(SpinBox1.Value);
      //
      for var j: integer := 1 to LHowManyItems do
        begin
          LBItem      := TListBoxItem.Create(Self);
          LBItem.Text := '... Item' + j.ToString;
          ListBox1.AddObject(LBItem);
          LBItemHeight := LBItem.Height; // if Item with distinct height, then needs some calc...
        end;
    end;
  //
  LItemHeight := ListBox1.ClientHeight - (LBGHeaderHeight + 1); // (LBGHeaderHeight + 1 = line-separator
  LItemHeight := (LItemHeight / (LHowManyItems + 1));           // LHowManyItems + Header
  //
  ListBox1.ItemHeight := LItemHeight;
  ListBox1.ListStyle  := TListStyle.Horizontal;
end;

initialization

ReportMemoryLeaksOnShutdown := true;

end.

 

 

 

bds_HNxsUzs3zr.gif

Edited by programmerdelphi2k
  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×