* * *

Author Topic: TListView column too narrow, not obeying setting  (Read 1272 times)

RedOctober

  • Full Member
  • ***
  • Posts: 218
TListView column too narrow, not obeying setting
« on: March 12, 2018, 04:20:14 am »
I have a TListView named lvwTrg with the following settings:

AutoWidthLastColumn = False, Columns = 1, CheckBoxes = False, SmallImages is assigned, ScrollBars = ssBoth, ViewStyle = vsList

The width of the single column is "stuck" at 58 (It reverts to 58 if I try to change it in the IDE).  It's AutoSize is set to False;
So, I set the column width at runtime programatically like this:

lvwTrg.Column[0].Width := 250;

Result:

The lvwTrg draws the 860 items in what I call "newspaper column" layout, filling the leftmost column vertically to the bottom of the window, then the next column from top to bottom, and so on, for about 50 colums and I use the horizontal scrollbar along the bottom to scroll to the right, to see all the columns.
This is what I want.  Works correctly.

Problem: 

The column width setting of 250 is not obeyed.  The colums are drawn only to about 75 pixels wide, so most of the item names are truncated with "..."

I have other TListviews with the exact same setting except for the "SmallImages", which draw the column width to the width that I set programmatically.
It's as if assigning the SmallImages causes the programatic setting of 250 wide to be ignored.

Question: 

How do I get the TListView to obey my width setting of 250 pixels?

Platform:  Lazarus 1.8.1, FPC 3.0.5

jamie

  • Hero Member
  • *****
  • Posts: 767
Re: TListView column too narrow, not obeying setting
« Reply #1 on: March 12, 2018, 04:58:53 am »
Tlistview has Columns Property that takes control over the column
  • if they are defined.


they are an array of TListColumn an that class has a MaxWidth and MinWidth for the column
and current width..

 Maybe that's your problem?

RedOctober

  • Full Member
  • ***
  • Posts: 218
Re: TListView column too narrow, not obeying setting
« Reply #2 on: March 12, 2018, 03:38:17 pm »
The min and max properties seem to have no effect.  I've set them to various values, leaving a spread between them  (like 125 and 150), but the TListView ignores that setting and still draws little narrow columns that chop off much of the caption text.  It seems having SmallImages assigned makes the column stuck at a "too narrow" value.

taazz

  • Hero Member
  • *****
  • Posts: 5081
Re: TListView column too narrow, not obeying setting
« Reply #3 on: March 12, 2018, 04:33:24 pm »
I have a TListView named lvwTrg with the following settings:

AutoWidthLastColumn = False, Columns = 1, CheckBoxes = False, SmallImages is assigned, ScrollBars = ssBoth, ViewStyle = vsList

The width of the single column is "stuck" at 58 (It reverts to 58 if I try to change it in the IDE).  It's AutoSize is set to False;
So, I set the column width at runtime programatically like this:

lvwTrg.Column[0].Width := 250;

Result:

The lvwTrg draws the 860 items in what I call "newspaper column" layout, filling the leftmost column vertically to the bottom of the window, then the next column from top to bottom, and so on, for about 50 colums and I use the horizontal scrollbar along the bottom to scroll to the right, to see all the columns.
This is what I want.  Works correctly.

Problem: 

The column width setting of 250 is not obeyed.  The colums are drawn only to about 75 pixels wide, so most of the item names are truncated with "..."

I have other TListviews with the exact same setting except for the "SmallImages", which draw the column width to the width that I set programmatically.
It's as if assigning the SmallImages causes the programatic setting of 250 wide to be ignored.

Question: 

How do I get the TListView to obey my width setting of 250 pixels?

Platform:  Lazarus 1.8.1, FPC 3.0.5
set ViewStyle to vsReport.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RedOctober

  • Full Member
  • ***
  • Posts: 218
Re: TListView column too narrow, not obeying setting
« Reply #4 on: March 12, 2018, 04:53:27 pm »
vsReport causes the items to be listed vertically only.  I need a "newspaper" type colum that wraps top to bottom then adds columns to the right, for infinity.

UPDATE:  PROBLEM SOLVED:  Don't use "SmallImages" for this situation.  Use "StateImages" and "StateIndex".  Then the column width calculation is correctly made to your setting.

taazz

  • Hero Member
  • *****
  • Posts: 5081
Re: TListView column too narrow, not obeying setting
« Reply #5 on: March 12, 2018, 05:12:26 pm »
Can't reproduce it in 1.8.2 with or with out the smallimage set it always scrolls the same way.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

RedOctober

  • Full Member
  • ***
  • Posts: 218
Re: TListView column too narrow, not obeying setting
« Reply #6 on: March 12, 2018, 05:44:23 pm »
Hi taazz,  Scrolling is not the problem.  Column width is the problem, which has been solved by using StateImages and StateIndex, but now I have another problem.  No matter what I set the StateIndex to, the image shown is always image zero.

In my test project, the assigned StateIndex shows the correct corresponding image in the TImageList.  However, in my real project, the image shown is always image zero.  Even when I copy and paste the exact TListView component and working code from the test project to my real project, it also displays the same incorrect behavior.  I'm wondering if there is something in the Uses clause that is mucking up my state images links.

RedOctober

  • Full Member
  • ***
  • Posts: 218
Re: TListView column too narrow, not obeying setting
« Reply #7 on: March 12, 2018, 05:47:44 pm »
After reading this... I'm wondering if I shd be using TListView at all.  Is there a better alternative?

http://forum.lazarus.freepascal.org/index.php/topic,37581.msg252965.html#msg252965


taazz

  • Hero Member
  • *****
  • Posts: 5081
Re: TListView column too narrow, not obeying setting
« Reply #8 on: March 12, 2018, 05:49:10 pm »
See attached image. SmallImages property is set to a 16x16 imagelist, no columns are set and everything works as per your specifications

I do not know any other control that can scroll horizontally sorry.
« Last Edit: March 12, 2018, 05:52:22 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

GetMem

  • Hero Member
  • *****
  • Posts: 3053
Re: TListView column too narrow, not obeying setting
« Reply #9 on: March 12, 2018, 05:57:07 pm »
VTV is far better in my opinion. You can search the forum for examples.

RedOctober

  • Full Member
  • ***
  • Posts: 218
Re: TListView column too narrow, not obeying setting
« Reply #10 on: March 12, 2018, 10:04:20 pm »
The StateIndex not displaying the correct icon problem has been solved.  As it turns out, if you assign the StateIndex after form create, but before formshow, then the StateIndex is stuck at 0 no matter what you set it at.  I moved the TListView population procedure call to the FormShow event and it works correctly.  No changes in code required.  Only took me all day to figure out what was going wrong.  Anyone got any comments as to why this problem occurs after create and before form show?  Bug?  Or is this expected behavior?

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus