Recent

Author Topic: Listbox columns. How to populate?  (Read 1502 times)

GlockG20

  • Newbie
  • Posts: 2
Listbox columns. How to populate?
« on: May 24, 2024, 02:17:35 am »
Hello, I am moving away from the XOJO IDE into the Lazarus / Pascal IDE for several reasons. I just started my foray  into this new real a week ago. That said, I am rather confused by some of the objects and how to populate them and so forth.

In my XOJO apps I have ListBoxes that have obviously multiple rows, but also varied number of columns. ( See Attached Image ). I have been digging around but I can't seem to find examples of how to do the same with Lazarus Listboxes. So... can I and if so ... how?


jamie

  • Hero Member
  • *****
  • Posts: 6735
Re: Listbox columns. How to populate?
« Reply #1 on: May 24, 2024, 02:24:07 am »
I don't know what type of listbox was being used in your previous tools, but the Tlistbox here isn't going to give you that kind of control.

You need to use a TStringGrid for that.
The only true wisdom is knowing you know nothing

GlockG20

  • Newbie
  • Posts: 2
Re: Listbox columns. How to populate?
« Reply #2 on: May 24, 2024, 02:27:51 am »
TStringGrid. Thank you! I'll play with that for a bit and see what I can accomplish! I just assumed a ListBox was "universal" in concept. Guess not!

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Listbox columns. How to populate?
« Reply #3 on: May 24, 2024, 03:29:04 am »
Since XOJO IDE does create a custom control, in Lazarus you would need to do same.
(ie: there is no control that matches yours 1:1 out-of-the-box)
Very adjustable but not the easiest to handle is the TListView component where I've attached a demo image from.
Thats how it looks after you set style to vsReport and turn GridLines on and added three colums.
Coloring cells is possible by OwnerDraw.
Coloring header is not possible, that is controlled by OS (at least on Windows)

While filling the cells is pretty easy, here the code I used for image:
Code: Pascal  [Select][+][-]
  1. var
  2.   LItem: TListItem;
  3.   i: Integer;
  4. begin
  5.   Randomize;
  6.   for i := 0 to 9 do
  7.     begin
  8.       LItem := ListView1.Items.Add;
  9.       LItem.Caption := IntToStr(Random(High(Word)));
  10.       LItem.SubItems.Add(IntToStr(Random(High(Word))));
  11.       LItem.SubItems.Add(IntToStr(Random(High(Word))));
  12.     end;
  13. end;
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

paweld

  • Hero Member
  • *****
  • Posts: 1268
Re: Listbox columns. How to populate?
« Reply #4 on: May 24, 2024, 11:12:37 am »
You can also use VirtualStringTree - sample in attachement
Best regards / Pozdrawiam
paweld

wp

  • Hero Member
  • *****
  • Posts: 12476
Re: Listbox columns. How to populate?
« Reply #5 on: May 24, 2024, 11:50:21 am »
I'd say that VirtualStringTree is too complicated for a beginner.

As a "getting started" I am attaching a small project which displays some of your data in a TStringGrid.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11950
  • FPC developer.
Re: Listbox columns. How to populate?
« Reply #6 on: May 24, 2024, 12:14:55 pm »
Note that tlistbox is the basic box, TListView is the more complicated one.

(added later: Ouch, read over KodeZwerg already mentioning it )

 

TinyPortal © 2005-2018