|
|
|
|
|
Dicas
|
|
Visual Basic (Miscelâneas)
|
|
|
Título da Dica: Ajustar o ListView ao seu conteúdo
|
|
|
|
Postada em 9/5/2005 por Josefh Hennyere
'Componente: Microsoft Windows Common Control 6.0 (SP6) 'Objetos: ListView1, Command1 ' Option Explicit ' 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 Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long ' Const LVM_Min As Long = &H1000 Const LVM_SETCOLUMNWIDTH As Long = (LVM_Min + 30) Const LVSCW_AUTOSIZE As Long = -1 Const LVSCW_AUTOSIZE_USEHEADER As Long = -2 Sub AutoAjust() LockWindowUpdate ListView1.hWnd Dim i As Integer For i = 0 To ListView1.ColumnHeaders.Count SendMessage ListView1.hWnd, LVM_SETCOLUMNWIDTH, i, LVSCW_AUTOSIZE_USEHEADER LockWindowUpdate 0 Next End Sub
Private Sub Form_Load() ListView1.View = lvwReport ListView1.ColumnHeaders.Add 1, , "Character" ListView1.ColumnHeaders.Add 2, , "Role" ListView1.ListItems.Add 1, , "Homer Simpson" ListView1.ListItems(1).SubItems(1) = "Works at nuclear power plant" ListView1.ListItems.Add 2, , "Montgomery Burns" ListView1.ListItems(2).SubItems(1) = "Owner/boss of power plant" ListView1.ListItems.Add 3, , "Wayland Smithers" ListView1.ListItems(3).SubItems(1) = "Mr. Burns's secretary" ListView1.ListItems.Add 4, , "Apu Nahasateemapetalon" ListView1.ListItems(4).SubItems(1) = "Owns Kwik-E-Mart" ListView1.ListItems.Add 5, , "Clancey Wiggum" ListView1.ListItems(5).SubItems(1) = "Police chief" ListView1.ListItems.Add 6, , "Milhouse Van Houghton" ListView1.ListItems(6).SubItems(1) = "Bart's best friend" End Sub
|
|
|
|
|