Recent

Author Topic: Tab into ListBox (SOLVED)  (Read 18341 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Tab into ListBox (SOLVED)
« on: October 19, 2010, 01:43:03 pm »
var Lista_Prenotati: TListBox;

Lista_Prenotati.Items.Add('hello' + ^I + 'world');

Why do I see the spacing correctly in Linux and in Windows I see a square?! How do I get the Tab spacing?!

Does anyone know?
« Last Edit: October 20, 2010, 12:37:03 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

BlueIcaro

  • Hero Member
  • *****
  • Posts: 595
Re: Tab into ListBox
« Reply #1 on: October 19, 2010, 01:46:51 pm »
What is ^I?
Why a pointer?

/BlueIcaro
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Re: Tab into ListBox
« Reply #2 on: October 19, 2010, 02:05:28 pm »
Because i serch the problem into delphi forum and solution are: ^I. I tested Chr(9) but result is not good! Help me please


http://www.delphibasics.co.uk/RTL.asp?Name=Chr
« Last Edit: October 19, 2010, 02:11:52 pm by xinyiman »
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

BlueIcaro

  • Hero Member
  • *****
  • Posts: 595
Re: Tab into ListBox
« Reply #3 on: October 19, 2010, 02:20:00 pm »
The space in AScci Table is 32, so try:

Lista_Prenotati.Items.Add('hello' + #32 + 'world');

/BlueIcaro
Remenber, the lazarus wiki is your friend: http://wiki.lazarus.freepascal.org/Main_Page
General questions (several lenguages) http://wiki.lazarus.freepascal.org/

xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Re: Tab into ListBox
« Reply #4 on: October 19, 2010, 02:25:23 pm »
But I need the horizontal tab!

Ascii code #9 but it does not work
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

99Percent

  • Full Member
  • ***
  • Posts: 154
Re: Tab into ListBox
« Reply #5 on: October 19, 2010, 02:38:18 pm »
It might be related to UTF8/ASCII encoding. Try using different types of strings: AnsiString, ShortString, etc.

xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Re: Tab into ListBox
« Reply #6 on: October 19, 2010, 03:00:18 pm »
I tested: string, ansistring, shortstring. Is not a solution!  :'( :o
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

José Mejuto

  • Full Member
  • ***
  • Posts: 136
Re: Tab into ListBox
« Reply #7 on: October 19, 2010, 07:46:35 pm »
var Lista_Prenotati: TListBox;

Lista_Prenotati.Items.Add('hello' + ^I + 'world');

Why do I see the spacing correctly in Linux and in Windows I see a square?! How do I get the Tab spacing?!

Does anyone know?

Hello,

AFAIK Windows ListBox does not honor TAB character, or any other control character. All of them are rendered as a square box. This is windows behavior, not Lazarus decision.

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Tab into ListBox
« Reply #8 on: October 19, 2010, 08:33:31 pm »
guys,  I don't mean to be rude, but if you don't understand what xinyiman asked, do not reply.

the thing is, delphi listbox has a property called TabWidth. you set it to, say 200, then do something like:
Code: [Select]
LB.Items.Add('first column' + #9 + 'second column' + #9 + 'second column');  // #9 = tab
LB.Items.Add('sdfasdf' + ^I + 'sd sdfsd' + ^I + 'sdf sadfasdf');  // sure, ^I works too
LB.Items.Add('first column'#9'second column'#9'second column');

and you get the contents nicely aligned in three columns. you should fix tab width in OnResize event (200 units aren't 200 pixels, but you can easily find correspondence).

 - - - - (explanation done, now the post answer)  - - - -

lazarus listbox does not have that property because some widgetsets do not support it. sorry. make listbox ownerdrawn if you really need that option or use listview. i'd use stringgrid (hide the gridlines, add rowselect option and you're good).
« Last Edit: October 19, 2010, 08:35:10 pm by ivan17 »

xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Re: Tab into ListBox
« Reply #9 on: October 20, 2010, 06:49:34 am »
Make me an example please?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

ivan17

  • Full Member
  • ***
  • Posts: 173
Re: Tab into ListBox
« Reply #10 on: October 20, 2010, 11:22:48 am »
Make me an example please?

well you could have been more specific, but i'll try to give you a good guess...
throw a stringgrid onto an empty form; change these properties:
Code: [Select]
object Grid1: TStringGrid
  Anchors = [akTop, akLeft, akRight, akBottom]
  AutoAdvance = aaDown
  ColCount = 2
  FixedCols = 0
  Flat = True
  MouseWheelOption = mwGrid
  Options = [goFixedVertLine, goFixedHorzLine, goColSizing,
                      goRowSelect, goThumbTracking, goSmoothScroll]
  RowCount = 11
  ScrollBars = ssAutoVertical
end

now add these three methods:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Grid1HeaderSized(Sender: TObject; IsColumn: Boolean; Index: Integer);
  2. begin                                   {$HINTS OFF}
  3.   Grid1.ColWidths[1] := Grid1.ClientWidth - Grid1.ColWidths[0];
  4. end;                                      {$HINTS ON}
  5.  
  6. procedure TForm1.Grid1Resize(Sender: TObject);
  7. begin
  8.   Grid1.ColWidths[0] := Grid1.ClientWidth - Grid1.ColWidths[1];
  9. end;
  10.  
  11. procedure TForm1.FormCreate(Sender: TObject);
  12. begin
  13.   Grid1.Rows[0].Text := 'header1' + #13 + 'header2';  // both cells at once
  14. end;
  15.  

that should do it. try adding the grid lines and see if you prefer them. or alternate color.
here's an example proc that will fill the grid a bit:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.   Grid1.RowCount := 16;
  4.   Grid1.Cols[1].Text := 'header2'#13'12'#13'23'#13'34'#13'45'#13'56'#13'67'#13'78'#13'89'#13'90'#13'01'#13'12'#13'23'#13'34'#13'45'#13'56';
  5.   Grid1.Cells[0,15] := 'last row';
  6.   Grid1.Cells[0,1] := 'first row';
  7. end;
  8.  


xinyiman

  • Hero Member
  • *****
  • Posts: 2092
    • Lazarus and Free Pascal italian community
Re: Tab into ListBox
« Reply #11 on: October 20, 2010, 12:36:46 pm »
Thank you!  ;)
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018