LISTVIEW - AUTOSIZE
Peguei na net esse código, ele deixa a largura da coluna do listview ajustada ao conteúdo, mas queria que o columreader aparecesse caso o conteúdo da coluna seja menor que ele.
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 Character Character Character 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
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 Character Character Character 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
é só para que o nome do column header não suma caso o coteúdo seja menor que ele
Na mão
[ô]Ajustar ListView
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
Sub AutoAjust(ByRef Objeto As Object)
[ô]Função: Auto Ajust
[ô]Finalidade: Tem como objetivo formatar automaticamente as colunas dos listview baseado no cabeçalho e conteudo
[ô]URL: http://binaryworld.net/Main/CodeDetail.aspx?CodeId=3640
Const SET_COLUMN_WIDTH As Long = 4126
Const AUTOSIZE_USEHEADER As Long = -2
Dim lngColumn As Long
For lngColumn = 0 To (Objeto.ColumnHeaders.Count - 1)
Call SendMessage(Objeto.hwnd, SET_COLUMN_WIDTH, lngColumn, ByVal AUTOSIZE_USEHEADER)
Next lngColumn
End Sub
Valew Brother, funcionou direitinho.
Obrigado
Obrigado
Tópico encerrado , respostas não são mais permitidas