List View Horizontal Scroll 
Author Message
 List View Horizontal Scroll

Hello,

I am having some difficulty with the List View control. When I put the List
View in Report view I have one main item with subitems. The area of the main
item is filled with information about the object. This is a variable length
string. When the string is too long it cut the text and append an ellypsis
(...) at the end.

I need to be able to stretch this main item area to fit the longest object
description I have. How do I go about accomplishing this? I thought I could
use a fixed length font and find out what the pixel size is for the font and
then multiply it by the length of the string and then use that value as the
width of the Main Item column... Does anyone know a a simpler solution???

Any help is much appreciated...

Jonas Gorauskas



Wed, 12 Nov 2003 04:35:08 GMT  
 List View Horizontal Scroll
You don't even have to use a fixed width font.  Try setting the form's font
to the same as the list items (MS Sans Serif 8pt I believe is the default).
Then use the Form.TextWidth method to get the width of the longest string of
text.  Then you should be able to set the column width accordingly.


Quote:
> Hello,

> I am having some difficulty with the List View control. When I put the
List
> View in Report view I have one main item with subitems. The area of the
main
> item is filled with information about the object. This is a variable
length
> string. When the string is too long it cut the text and append an ellypsis
> (...) at the end.

> I need to be able to stretch this main item area to fit the longest object
> description I have. How do I go about accomplishing this? I thought I
could
> use a fixed length font and find out what the pixel size is for the font
and
> then multiply it by the length of the string and then use that value as
the
> width of the Main Item column... Does anyone know a a simpler solution???

> Any help is much appreciated...

> Jonas Gorauskas



Wed, 12 Nov 2003 05:18:22 GMT  
 List View Horizontal Scroll

enlighten us with :

Quote:
>You don't even have to use a fixed width font.  Try setting the form's font
>to the same as the list items (MS Sans Serif 8pt I believe is the default).
>Then use the Form.TextWidth method to get the width of the longest string of
>text.  Then you should be able to set the column width accordingly.

Also you might want to ensure that the column header text isn't
truncated, so include the columnheader text in the list of strings
when performing the calculation. Also, for every column that contains
icons, add 315 (in twips) to the maximum string length.

An alternative, which is kind of a hack, is to simply set the focus to
the listview after loading the items, and do a SendKeys "^{+}" (ctrl
and +), although this method won't compensate for the columnheader
text.

        J.
        Jeremiah D. Seitz
        Porch karaoke king and the guy who runs with 8< scissors >8
        Omega Techware
        http://omegatechware.hypermart.net



Thu, 13 Nov 2003 03:37:08 GMT  
 List View Horizontal Scroll
Ahh, yes the column header width bug.  Adding 315 twips isn't exactly a
great idea because twips vary from system to system.  Pixels are fixed, but
twips depend on the resolution and monitor size (if it is known).  There are
always 1440 twips per inch, so twips/pixel can vary.  Anyway, the way to get
and set column widths that doesn't suffer the width bug is to use
SendMessage with LVM_GETCOLUMNWIDTH and LVM_SETCOLUMNWIDTH:

    Public Declare Function SendMessageLong Lib "user32.dll" Alias
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As
Long, ByVal lParam As Long) As Long

    Public Const LVM_FIRST = &H1000
    Public Const LVM_GETCOLUMNWIDTH = (LVM_FIRST + 29)
    Public Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)

    Width = SendMessageLong(ListView.hWnd, LVM_GETCOLUMNWIDTH, ColumnIndex,
0))
    Call SendMessageLong(ListView.hWnd, LVM_SETCOLUMNWIDTH, ColumnIndex,
Width)

ColumnIndex is zero-based and Width is in pixels (always).  If you need to
convert between pixels and twips, use Screen.TwipsPerPixelX and Y.



enlighten us with :

Quote:
>You don't even have to use a fixed width font.  Try setting the form's font
>to the same as the list items (MS Sans Serif 8pt I believe is the default).
>Then use the Form.TextWidth method to get the width of the longest string
of
>text.  Then you should be able to set the column width accordingly.

Also you might want to ensure that the column header text isn't
truncated, so include the columnheader text in the list of strings
when performing the calculation. Also, for every column that contains
icons, add 315 (in twips) to the maximum string length.

An alternative, which is kind of a hack, is to simply set the focus to
the listview after loading the items, and do a SendKeys "^{+}" (ctrl
and +), although this method won't compensate for the columnheader
text.

J.
Jeremiah D. Seitz
Porch karaoke king and the guy who runs with 8< scissors >8
Omega Techware
http://omegatechware.hypermart.net



Thu, 13 Nov 2003 04:46:23 GMT  
 List View Horizontal Scroll

enlighten us with :

Quote:
>Ahh, yes the column header width bug.  Adding 315 twips isn't exactly a
>great idea because twips vary from system to system.  Pixels are fixed, but
>twips depend on the resolution and monitor size (if it is known).  There are
>always 1440 twips per inch, so twips/pixel can vary.  Anyway, the way to get
>and set column widths that doesn't suffer the width bug is to use
>SendMessage with LVM_GETCOLUMNWIDTH and LVM_SETCOLUMNWIDTH:

>    Public Declare Function SendMessageLong Lib "user32.dll" Alias
>"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As
>Long, ByVal lParam As Long) As Long

>    Public Const LVM_FIRST = &H1000
>    Public Const LVM_GETCOLUMNWIDTH = (LVM_FIRST + 29)
>    Public Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30)

>    Width = SendMessageLong(ListView.hWnd, LVM_GETCOLUMNWIDTH, ColumnIndex,
>0))
>    Call SendMessageLong(ListView.hWnd, LVM_SETCOLUMNWIDTH, ColumnIndex,
>Width)

>ColumnIndex is zero-based and Width is in pixels (always).  If you need to
>convert between pixels and twips, use Screen.TwipsPerPixelX and Y.

I stand corrected. Thanks Doug!

        J.
        Jeremiah D. Seitz
        Porch karaoke king and the guy who runs with 8< scissors >8
        Omega Techware
        http://omegatechware.hypermart.net



Thu, 13 Nov 2003 15:21:39 GMT  
 List View Horizontal Scroll
Hello,

Thank you all for your tips... Very helpful insights!

Jonas

Quote:

> Hello,

> I am having some difficulty with the List View control. When I put the List
> View in Report view I have one main item with subitems. The area of the main
> item is filled with information about the object. This is a variable length
> string. When the string is too long it cut the text and append an ellypsis
> (...) at the end.

> I need to be able to stretch this main item area to fit the longest object
> description I have. How do I go about accomplishing this? I thought I could
> use a fixed length font and find out what the pixel size is for the font and
> then multiply it by the length of the string and then use that value as the
> width of the Main Item column... Does anyone know a a simpler solution???

> Any help is much appreciated...

> Jonas Gorauskas



Mon, 24 Nov 2003 23:26:38 GMT  
 List View Horizontal Scroll
I see you've been working with ListView Control.
Maybe you could help me with this problem?? :

When I fill up the ListView, it scolls down. I want it, when filled up, to
be all scrolled up. Do you know how to do that??

Thanks,
Robbert


Quote:
> Hello,

> Thank you all for your tips... Very helpful insights!

> Jonas




Quote:
> > Hello,

> > I am having some difficulty with the List View control. When I put the
List
> > View in Report view I have one main item with subitems. The area of the
main
> > item is filled with information about the object. This is a variable
length
> > string. When the string is too long it cut the text and append an
ellypsis
> > (...) at the end.

> > I need to be able to stretch this main item area to fit the longest
object
> > description I have. How do I go about accomplishing this? I thought I
could
> > use a fixed length font and find out what the pixel size is for the font
and
> > then multiply it by the length of the string and then use that value as
the
> > width of the Main Item column... Does anyone know a a simpler
solution???

> > Any help is much appreciated...

> > Jonas Gorauskas



Mon, 24 Nov 2003 23:52:32 GMT  
 List View Horizontal Scroll
    ListView1.ListItems(1).EnsureVisible

Dag.


Quote:
> I see you've been working with ListView Control.
> Maybe you could help me with this problem?? :

> When I fill up the ListView, it scolls down. I want it, when filled up, to
> be all scrolled up. Do you know how to do that??

> Thanks,
> Robbert



> > Hello,

> > Thank you all for your tips... Very helpful insights!

> > Jonas



> > > Hello,

> > > I am having some difficulty with the List View control. When I put the
> List
> > > View in Report view I have one main item with subitems. The area of
the
> main
> > > item is filled with information about the object. This is a variable
> length
> > > string. When the string is too long it cut the text and append an
> ellypsis
> > > (...) at the end.

> > > I need to be able to stretch this main item area to fit the longest
> object
> > > description I have. How do I go about accomplishing this? I thought I
> could
> > > use a fixed length font and find out what the pixel size is for the
font
> and
> > > then multiply it by the length of the string and then use that value
as
> the
> > > width of the Main Item column... Does anyone know a a simpler
> solution???

> > > Any help is much appreciated...

> > > Jonas Gorauskas



Tue, 25 Nov 2003 04:02:00 GMT  
 List View Horizontal Scroll

Quote:
> I see you've been working with ListView Control.
> Maybe you could help me with this problem?? :

> When I fill up the ListView, it scolls down. I want it, when filled up, to
> be all scrolled up. Do you know how to do that??

After filling the list, set the selected item to the first item in the list
and tell the control to make sure it's visible.  Something like:

  On Error Resume Next
  With ListView1
    Set .SelectedItem = .ListItems.Item(0)
    .SelectedItem.EnsureVisible
  End With

-- Roger
The Daily Exclaimer: http://www.exclaimer.com/
New - Thrilling - Exciting - Provocative - Fictional



Tue, 25 Nov 2003 03:45:03 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. VB4, list boxes, and horizontal scroll bars CHALLENGE!

2. Need a List Box with a Horizontal Scroll Bar

3. Horizontal Scroll in a list box

4. Adding horizontal scroll bars to a dir list box

5. Horizontal Scroll bar in List Box

6. adding horizontal scroll bar to list box

7. adding horizontal scroll bar to list box

8. Adding a horizontal scroll bar to File and Dir List Box

9. VB4, list boxes, and horizontal scroll bars CHALLENGE!

10. Ri: Horizontal scroll of 2 list b

11. Horizontal scroll of 2 list box controls

12. List Box: Adding a Horizontal and Vertical Scroll Bar

 

 
Powered by phpBB® Forum Software