Recent

Author Topic: Item grouping in ListView or ListBox, or even in ComboBoxes  (Read 6315 times)

Klamber|ext.

  • Newbie
  • Posts: 5
Item grouping in ListView or ListBox, or even in ComboBoxes
« on: October 01, 2014, 12:06:31 am »
Hey, can anyone shed some light into this problem.

I'm not very advanced in Lazarus. I tend to to do more of web work, but from time to time I fire up freepascal and try to make something (Pascal was my first language).


I have been searching around for a method for making a listbox with it's items grouped like on the example image included in attachment, but i am unable to find the right thing. In HTML it's called option grouping.


Thanks!

ggallo

  • New Member
  • *
  • Posts: 13
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #1 on: October 01, 2014, 08:22:44 am »
I think classic LCL ListBox can't do that. Maybe TTreeView will do it for you, if you need a listbox type control with nested contents.
But I don't think standard LCL contains any control that do this in a ComboBox alternative.
Windows 7 64 bit | openSuSE 12.3 32 bit
Lazarus 1.2.4 | fpc 2.6.4 | Win32/64 | Linux gtk2

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #2 on: October 01, 2014, 09:10:30 am »
The new component TComboboxEx has an Indent property for each item. It does not yet provide custom painting to get the main items bold and italic, though. But this component is really very new and is certainly not yet in its final state.


Klamber|ext.

  • Newbie
  • Posts: 5
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #3 on: October 01, 2014, 11:06:04 am »
I fiddled around with TTreeView, but i could not style the parent nodes.
I used something like this in a OnAdvancedCustomDrawItem event:

Code: [Select]
...
if Node.Parent = nil then begin
  Sender.Canvas.Font.Style = [fsBold];
end;
DefaultDraw := True;
...

To me it seems that the font style has nothing to do with the Node itself here,
but it came up in my searches and seemed to work on other people. Or does it in Delphi ?
It set the whole TreeView's text to bold, what was kind of expected :D

Might have I been misinformed ?

Perhaps I should mention Lazarus version: 1.2.4 (win32)

Thanks!

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #4 on: October 01, 2014, 11:15:01 am »
Code: [Select]
procedure TForm1.TreeView1CustomDrawItem(Sender: TCustomTreeView;
  Node: TTreeNode; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  if Node.Level = 0
    then Sender.canvas.Font.Style := [fsBold, fsItalic]
    else Sender.Canvas.Font.style := [];
end;

And you must remove ShowLines and ShowRoot from the TreeView's Options to hide the connecting lines and the node triangle.

Quote
It set the whole TreeView's text to bold
You have to reset the Font style for the other nodes - see above.

BeniBela

  • Hero Member
  • *****
  • Posts: 905
    • homepage
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #5 on: October 01, 2014, 11:25:27 am »
You can try my TreeListView

Klamber|ext.

  • Newbie
  • Posts: 5
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #6 on: October 01, 2014, 11:32:21 am »
Whoa!  :o

I can see clearly now. 

Thanks, you have been very helpful, wp!

 I will look into it, BeniBela.

Blaazen

  • Hero Member
  • *****
  • Posts: 3237
  • POKE 54296,15
    • Eye-Candy Controls
Re: Item grouping in ListView or ListBox, or even in ComboBoxes
« Reply #7 on: October 01, 2014, 01:52:43 pm »
Quote
The new component TComboboxEx has an Indent property for each item. It does not yet provide custom painting to get the main items bold and italic, though. But this component is really very new and is certainly not yet in its final state.

TComboBoxEx is implemented to be as compatible with Delphi as possible. Delphi7 has not such feature (nor OnDrawItem event published) so Lazarus version hasn't it too.

Note: I wrote the initial implementation but now it is part of Lazarus so anyone can work on it.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

 

TinyPortal © 2005-2018