Board index » cppbuilder » TListView Column Width parameter not functioning

TListView Column Width parameter not functioning


2005-09-07 08:42:50 AM
cppbuilder17
Hello,
I am using BCB 6.0 with Update #4 installed on WinXP SP2.
I am using a TListView (named RRFileList) with ViewStyle = vsReport with
only one column. I would like the column to be at least as wide as the
listview, but to automatically expand (and add a horizontal scrollbar) if
longer items are added, and contract when they are removed (although I can
live without the latter).
I am initially setting the width as:
RRFileList->Column[0]->Width = RRFileList->ClientWidth;
Then when I add (or remove) an item:
//autosize column
RRFileList->Column[0]->Width = -1;
//if column is smaller than window, cancel autosize and set width
manually
if(RRFileList->Column[0]->Width < RRFileList->ClientWidth)
RRFileList->Column[0]->Width = RRFileList->ClientWidth;
The problem I am having is that once I set the width parameter to -1, it
stays at this value and does not change, thus the if statment always
evaluates to true and the column never resizes. According to the BCB Help
files, the read-only property WidthType is supposed to retain the -1 value,
while width is supposed to reflect the actual current width of the column.
This is not what seems to be happening...
I have also tried setting the MinWidth property equal to
RRFileList->ClientWidth but it will still autosize to less than this value.
Any suggestions would be greatly appreciated.
Thanks,
-Benjamin Herreid
 
 

Re:TListView Column Width parameter not functioning

Hi Benjamin,
This sounds like a bug. A workaround is to use the
LVM_GETCOLUMNWIDTH message to retrieve the current column width. See
tinyurl.com/dykfl
HTH,
C++Builder Developer's Journal
bcbjournal.com
BCB Commonly Asked Questions
bcbjournal.com/bcbcaq
Benjamin Herreid wrote:
Quote
The problem I am having is that once I set the width parameter to -1, it
stays at this value and does not change, thus the if statment always
evaluates to true and the column never resizes.
 

Re:TListView Column Width parameter not functioning

That worked perfectly, thank you very much.
And just for the record, the autosize only works when the column expands,
not contracts. So in my item removal code I just set the column width to
zero, then back to negative one and did the width check. Works exactly how
I wanted it to.
Thanks again!
-Benjamin
 

{smallsort}