colume width of listview in List mode
Author |
Message |
Pengcheng Zo #1 / 8
|
 colume width of listview in List mode
hi, When I use ListView in its "List" mode, it will display the items in multiple columns, some long items are truncated automatically. Just wonder is there anyway to control the column length? Thanks in advance.
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
Randy Birc #2 / 8
|
 colume width of listview in List mode
Once the control has been filled, call AdjustColumnWidths : 'general declarations Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (Destination As Any, Source As Any, _ ByVal Length As Long) Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Private Const LVSCW_AUTOSIZE = -1 Private Const LVSCW_AUTOSIZE_USEHEADER = -2 Private Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30) 'routines: Private Sub AdjustColumnWidths() Dim col2adjust As Long For col2adjust = 0 To ListView1.ColumnHeaders.Count - 1 Call SendMessage(ListView1.hwnd, _ LVM_SETCOLUMNWIDTH, _ col2adjust, _ ByVal MAKELPARAM(LVSCW_AUTOSIZE, 0)) Next End Sub Private Function MAKELPARAM(wLow As Long, wHigh As Long) As Long 'Combines two integers into a long integer MAKELPARAM = MAKELONG(wLow, wHigh) End Function Private Function MAKELONG(wLow As Long, wHigh As Long) As Long MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh)) End Function Public Function LoWord(dwValue As Long) As Integer CopyMemory LoWord, dwValue, 2 End Function -- Randy Birch, MVP Visual Basic http://www.mvps.org/vbnet/ http://www.mvps.org/ccrp/
| hi, | | When I use ListView in its "List" mode, it will display the items in | multiple columns, some long items are truncated automatically. Just wonder | is there anyway to control the column length? | | Thanks in advance. | |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
Randy Birc #3 / 8
|
 colume width of listview in List mode
Damn .. I read that as in report mode. -- Randy Birch, MVP Visual Basic http://www.mvps.org/vbnet/ http://www.mvps.org/ccrp/
| hi, | | When I use ListView in its "List" mode, it will display the items in | multiple columns, some long items are truncated automatically. Just wonder | is there anyway to control the column length? | | Thanks in advance. | |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
DWilliam #4 / 8
|
 colume width of listview in List mode
Don't worry too much... I needed that BAD for report mode! Thanks, DWilliams
Quote: > Damn .. I read that as in report mode. > -- > Randy Birch, MVP Visual Basic > http://www.mvps.org/vbnet/ > http://www.mvps.org/ccrp/
> | hi, > | > | When I use ListView in its "List" mode, it will display the items in > | multiple columns, some long items are truncated automatically. Just wonder > | is there anyway to control the column length? > | > | Thanks in advance. > | > |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
Randy Birc #5 / 8
|
 colume width of listview in List mode
The AdjustColumnWidths method was for Report view. Add this instead for List view ... Private Sub AdjustListColumnWidth() Dim twidth As Long Dim lastWidth As Long Dim x As Long ListView1.Parent.ScaleMode = vbPixels ListView1.ListItems(1).EnsureVisible For x = 1 To ListView1.ListItems.Count twidth = TextWidth(ListView1.ListItems.item(x).Text) If twidth > lastWidth Then lastWidth = twidth Next Call SendMessage(ListView1.hwnd, _ LVM_SETCOLUMNWIDTH, _ 0, _ ByVal lastWidth) ListView1.Parent.ScaleMode = vbTwips ListView1.Refresh End Sub -- Randy Birch, MVP Visual Basic http://www.mvps.org/vbnet/ http://www.mvps.org/ccrp/
| Once the control has been filled, call AdjustColumnWidths : | | 'general declarations | | Private Declare Sub CopyMemory Lib "kernel32" _ | Alias "RtlMoveMemory" _ | (Destination As Any, Source As Any, _ | ByVal Length As Long) | | Private Declare Function SendMessage Lib "user32" _ | Alias "SendMessageA" _ | (ByVal hwnd As Long, _ | ByVal wMsg As Long, _ | ByVal wParam As Long, _ | lParam As Any) As Long | | Private Const LVSCW_AUTOSIZE = -1 | Private Const LVSCW_AUTOSIZE_USEHEADER = -2 | Private Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30) | | 'routines: | | Private Sub AdjustColumnWidths() | | Dim col2adjust As Long | | For col2adjust = 0 To ListView1.ColumnHeaders.Count - 1 | | Call SendMessage(ListView1.hwnd, _ | LVM_SETCOLUMNWIDTH, _ | col2adjust, _ | ByVal MAKELPARAM(LVSCW_AUTOSIZE, 0)) | | Next | | End Sub | | | Private Function MAKELPARAM(wLow As Long, wHigh As Long) As Long | | 'Combines two integers into a long integer | MAKELPARAM = MAKELONG(wLow, wHigh) | | End Function | | | Private Function MAKELONG(wLow As Long, wHigh As Long) As Long | | MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh)) | | End Function | | | Public Function LoWord(dwValue As Long) As Integer | | CopyMemory LoWord, dwValue, 2 | | End Function | | -- | | Randy Birch, MVP Visual Basic | | http://www.mvps.org/vbnet/ | http://www.mvps.org/ccrp/
| |
| | hi, | | | | When I use ListView in its "List" mode, it will display the items in | | multiple columns, some long items are truncated automatically. Just wonder | | is there anyway to control the column length? | | | | Thanks in advance. | | | | | |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
Randy Birc #6 / 8
|
 colume width of listview in List mode
Glad it helped someone. Note that the only difference between the two possible resize messages is that the _USEHEADER one, when passed the last column in the listview, will cause that column to take up all remaining space in the control. It does not man that the column will resize to the width of the column header text as it implies. For example, if the LV was 600 wide and had 4 columns, and the max width for 0, 1 and 2 ended up being 100 each, sending the _AUTOSIZE message would cause the last column to size to the longest item's width. If AUTOSIZE_USEHEADER was passed instead, it (the fourth column) would occupy the remaining 300 of the width. And remember that with the API the columns are 0-based. -- Randy Birch, MVP Visual Basic http://www.mvps.org/vbnet/ http://www.mvps.org/ccrp/
| Don't worry too much... | | I needed that BAD for report mode! | | Thanks, | DWilliams | |
| > Damn .. I read that as in report mode. | > | > -- | > | > Randy Birch, MVP Visual Basic | > | > http://www.mvps.org/vbnet/ | > http://www.mvps.org/ccrp/
| > | >
| > | hi, | > | | > | When I use ListView in its "List" mode, it will display the items in | > | multiple columns, some long items are truncated automatically. Just | wonder | > | is there anyway to control the column length? | > | | > | Thanks in advance. | > | | > | | > | > | |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
DWilliam #7 / 8
|
 colume width of listview in List mode
Noted... Thanks again, DWilliams
Quote: > Glad it helped someone. Note that the only difference between the two > possible resize messages is that the _USEHEADER one, when passed the last > column in the listview, will cause that column to take up all remaining > space in the control. It does not man that the column will resize to the > width of the column header text as it implies. > For example, if the LV was 600 wide and had 4 columns, and the max width for > 0, 1 and 2 ended up being 100 each, sending the _AUTOSIZE message would > cause the last column to size to the longest item's width. If > AUTOSIZE_USEHEADER was passed instead, it (the fourth column) would occupy > the remaining 300 of the width. And remember that with the API the columns > are 0-based. > -- > Randy Birch, MVP Visual Basic > http://www.mvps.org/vbnet/ > http://www.mvps.org/ccrp/
> | Don't worry too much... > | > | I needed that BAD for report mode! > | > | Thanks, > | DWilliams > | > |
> | > Damn .. I read that as in report mode. > | > > | > -- > | > > | > Randy Birch, MVP Visual Basic > | > > | > http://www.mvps.org/vbnet/ > | > http://www.mvps.org/ccrp/
> | > > | >
> | > | hi, > | > | > | > | When I use ListView in its "List" mode, it will display the items in > | > | multiple columns, some long items are truncated automatically. Just > | wonder > | > | is there anyway to control the column length? > | > | > | > | Thanks in advance. > | > | > | > | > | > > | > > | > |
|
Sun, 07 Jul 2002 03:00:00 GMT |
|
 |
Pengcheng Zo #8 / 8
|
 colume width of listview in List mode
It works! Thanks a lot for the help.
Quote: > The AdjustColumnWidths method was for Report view. Add this instead for List > view ... > Private Sub AdjustListColumnWidth() > Dim twidth As Long > Dim lastWidth As Long > Dim x As Long > ListView1.Parent.ScaleMode = vbPixels > ListView1.ListItems(1).EnsureVisible > For x = 1 To ListView1.ListItems.Count > twidth = TextWidth(ListView1.ListItems.item(x).Text) > If twidth > lastWidth Then lastWidth = twidth > Next > Call SendMessage(ListView1.hwnd, _ > LVM_SETCOLUMNWIDTH, _ > 0, _ > ByVal lastWidth) > ListView1.Parent.ScaleMode = vbTwips > ListView1.Refresh > End Sub > -- > Randy Birch, MVP Visual Basic > http://www.mvps.org/vbnet/ > http://www.mvps.org/ccrp/
> | Once the control has been filled, call AdjustColumnWidths : > | > | 'general declarations > | > | Private Declare Sub CopyMemory Lib "kernel32" _ > | Alias "RtlMoveMemory" _ > | (Destination As Any, Source As Any, _ > | ByVal Length As Long) > | > | Private Declare Function SendMessage Lib "user32" _ > | Alias "SendMessageA" _ > | (ByVal hwnd As Long, _ > | ByVal wMsg As Long, _ > | ByVal wParam As Long, _ > | lParam As Any) As Long > | > | Private Const LVSCW_AUTOSIZE = -1 > | Private Const LVSCW_AUTOSIZE_USEHEADER = -2 > | Private Const LVM_SETCOLUMNWIDTH = (LVM_FIRST + 30) > | > | 'routines: > | > | Private Sub AdjustColumnWidths() > | > | Dim col2adjust As Long > | > | For col2adjust = 0 To ListView1.ColumnHeaders.Count - 1 > | > | Call SendMessage(ListView1.hwnd, _ > | LVM_SETCOLUMNWIDTH, _ > | col2adjust, _ > | ByVal MAKELPARAM(LVSCW_AUTOSIZE, 0)) > | > | Next > | > | End Sub > | > | > | Private Function MAKELPARAM(wLow As Long, wHigh As Long) As Long > | > | 'Combines two integers into a long integer > | MAKELPARAM = MAKELONG(wLow, wHigh) > | > | End Function > | > | > | Private Function MAKELONG(wLow As Long, wHigh As Long) As Long > | > | MAKELONG = LoWord(wLow) Or (&H10000 * LoWord(wHigh)) > | > | End Function > | > | > | Public Function LoWord(dwValue As Long) As Integer > | > | CopyMemory LoWord, dwValue, 2 > | > | End Function > | > | -- > | > | Randy Birch, MVP Visual Basic > | > | http://www.mvps.org/vbnet/ > | http://www.mvps.org/ccrp/
> | > |
> | | hi, > | | > | | When I use ListView in its "List" mode, it will display the items in > | | multiple columns, some long items are truncated automatically. Just > wonder > | | is there anyway to control the column length? > | | > | | Thanks in advance. > | | > | | > | > |
|
Mon, 08 Jul 2002 03:00:00 GMT |
|
|
|