ListView column width = ListView width ? 
Author Message
 ListView column width = ListView width ?

Hi there,

this is maybe a pretty dumb question but I can't find a proper solution: I
want my listview (with only one column in it) to display this very column in
the entire width of the listview. I thought that a statement like:

lvListView.ColumnHeaders.Item(1).Width = .lvListView.Width

does work, but it doesn't.

Can anyone help me, please?

TIA,
Andre



Tue, 01 Jul 2003 18:38:32 GMT  
 ListView column width = ListView width ?
Easiest sure-fire way ....

Const LVM_FIRST As Long = &H1000
Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Const LVSCW_AUTOSIZE_USEHEADER As Long = -2

Call SendMessage(ListView1.hwnd, _
                 LVM_SETCOLUMNWIDTH, _
                 0, _
                 ByVal LVSCW_AUTOSIZE_USEHEADER)

Call this after you add the data to the listview. It will resize the column
to fit the display width, and will take into account the scrollbar if
visible. If you call it before adding the data the header will set to the lv
width without taking the scrollbar into account, if present.

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: Hi there,
:
: this is maybe a pretty dumb question but I can't find a proper solution: I
: want my listview (with only one column in it) to display this very column
in
: the entire width of the listview. I thought that a statement like:
:
: lvListView.ColumnHeaders.Item(1).Width = .lvListView.Width
:
: does work, but it doesn't.
:
: Can anyone help me, please?
:
: TIA,
: Andre
:
:
:



Wed, 02 Jul 2003 08:02:29 GMT  
 ListView column width = ListView width ?
Hey Randy,

first of all thanks alot for answering!

Quote:
> Easiest sure-fire way ....

> Const LVM_FIRST As Long = &H1000
> Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
> Const LVSCW_AUTOSIZE_USEHEADER As Long = -2

> Call SendMessage(ListView1.hwnd, _
>                  LVM_SETCOLUMNWIDTH, _
>                  0, _
>                  ByVal LVSCW_AUTOSIZE_USEHEADER)

> Call this after you add the data to the listview. It will resize the
column
> to fit the display width, and will take into account the scrollbar if
> visible. If you call it before adding the data the header will set to the
lv
> width without taking the scrollbar into account, if present.

This didn't work. I called the function before I added the data. All I did
was adding one single column header to the empty listview. This very column
header is the one that should fit to the size of the listview control.

The effect of calling the SendMessage function is the same as using what I
typed before:

lvListView.ColumnHeaders.Item(1).Width = .lvListView.Width

So ... nothing changed.

I'm using VB6.0 SP4 if this is any help. Thanks alot,

Andre



Fri, 04 Jul 2003 17:19:19 GMT  
 ListView column width = ListView width ?
Try calling it after. The LVSCW_AUTOSIZE_USEHEADER message is a bit
misleading in name ... this message instructs that, when the column is the
last (or only) column in the control, that it should occupy "all remaining"
header space. IOW, as wide as the control. I tested just that code before
posting, and it works. As I said, if you call it before, the header is the
width of the control. If you then add items that create the scrollbar, the
scrollbar will cover the end of the header. If you call it after, the
presence / absence of the scrollbar is taken into consideration.

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: Hey Randy,
:
: first of all thanks alot for answering!
:
: > Easiest sure-fire way ....
: >
: > Const LVM_FIRST As Long = &H1000
: > Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
: > Const LVSCW_AUTOSIZE_USEHEADER As Long = -2
: >
: > Call SendMessage(ListView1.hwnd, _
: >                  LVM_SETCOLUMNWIDTH, _
: >                  0, _
: >                  ByVal LVSCW_AUTOSIZE_USEHEADER)
: >
: > Call this after you add the data to the listview. It will resize the
: column
: > to fit the display width, and will take into account the scrollbar if
: > visible. If you call it before adding the data the header will set to
the
: lv
: > width without taking the scrollbar into account, if present.
:
: This didn't work. I called the function before I added the data. All I did
: was adding one single column header to the empty listview. This very
column
: header is the one that should fit to the size of the listview control.
:
: The effect of calling the SendMessage function is the same as using what I
: typed before:
:
: lvListView.ColumnHeaders.Item(1).Width = .lvListView.Width
:
: So ... nothing changed.
:
: I'm using VB6.0 SP4 if this is any help. Thanks alot,
:
: Andre
:
:
:
:
:



Fri, 04 Jul 2003 21:41:22 GMT  
 ListView column width = ListView width ?
Hey Randy,

Quote:
> Try calling it after. The LVSCW_AUTOSIZE_USEHEADER message is a bit
> misleading in name ... this message instructs that, when the column is the
> last (or only) column in the control, that it should occupy "all
remaining"
> header space. IOW, as wide as the control. I tested just that code before
> posting, and it works. As I said, if you call it before, the header is the
> width of the control. If you then add items that create the scrollbar, the
> scrollbar will cover the end of the header. If you call it after, the
> presence / absence of the scrollbar is taken into consideration.

thanks alot!

Calling SendMessage after (!) adding some listitems to the control works
fine. Now I all I need is to prevent re-sizing this single column.

Thanks again,
Andre



Fri, 04 Jul 2003 22:35:14 GMT  
 ListView column width = ListView width ?

Quote:
> Calling SendMessage after (!) adding some listitems to the control works
> fine.

Well, it worked fine. Now, 10 minutes later (without changing the code for
the control), it doesn't work anymore. It doesn'T matter whether I start the
application from the IDE or as a compiled EXE. HUM?!? There is no reason for
this kind of behavior, right?

Thanks,
Andre



Fri, 04 Jul 2003 22:57:35 GMT  
 ListView column width = ListView width ?
Right.

Did you perchance change the SendMessage declare? If you had a SendMessage
declare with ByVal lParam As Long (or Any), then changed that to lParam As
Long  (or anything else without the ByVal), and did not call the api passing
"ByVal LVSCW_AUTOSIZE_USEHEADER", then it won't work. Either pass ByVal in
the call, or create a specific aliased SendMessage that has ByVal lParam ...

Make sense?

--

Randy Birch
MVP Visual Basic

Take the vb.net poll at:
http://www.mvps.org/vbnet/
http://www.mvps.org/ccrp/

Please respond only to the newsgroups so all can benefit.


: > Calling SendMessage after (!) adding some listitems to the control works
: > fine.
:
: Well, it worked fine. Now, 10 minutes later (without changing the code for
: the control), it doesn't work anymore. It doesn'T matter whether I start
the
: application from the IDE or as a compiled EXE. HUM?!? There is no reason
for
: this kind of behavior, right?
:
: Thanks,
: Andre
:
:



Sat, 05 Jul 2003 05:07:41 GMT  
 ListView column width = ListView width ?

Quote:
> Did you perchance change the SendMessage declare?

No. In the entire project there's only one SendMessage declaration that I
took from WinApi32.txt. It's in the same module as the SendMessage call in
the subroutine.

If you see the little snippets from the code you'll see that everything
seems to be alright. You do make sense, of course. Still, it doesn't work
for me. I get the impression that something with my Visual Studio 6 is
screwed up. I'm using SP4 so I should be free from major bugs.

Thanks for your patience and help,
Andre

PS: Here's the code (it's all in one module) ..

Option Explicit

Const LVM_FIRST As Long = &H1000
Const LVM_SETCOLUMNWIDTH As Long = (LVM_FIRST + 30)
Const LVSCW_AUTOSIZE_USEHEADER As Long = -2

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Sub SubName()

  '..
  'With frmExplorer
  '..
  'Filling The ListView with Items ..
  '..

  'API Call, um Spaltenbreite an Control anzupassen
  Call SendMessage(.lvKompetenzen.hwnd, LVM_SETCOLUMNWIDTH, 0, ByVal
LVSCW_AUTOSIZE_USEHEADER)

  '..
  'End With
End Sub



Sat, 05 Jul 2003 16:52:12 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Total width of columns = Width of ListView

2. Total width of columns = Width of ListView

3. Total width of columns = Width of ListView

4. Total width of columns = Width of ListView

5. ListView.Width <> Sum of ColumnHeader widths

6. Preserving column widths in Listview

7. How to get the widths of the columns in a ListView

8. How to get control if you resize the width of a Column in a ListView

9. Listview: Auto set column width?

10. Column widths not "sticky" in ListView

11. ListView returning incorrect column width

12. How to lock column width in ListView?

 

 
Powered by phpBB® Forum Software