COMO ZEBRAR UMA LISTVIEW
Olá, colegas. Procurei tanto, tanto um exemplo de como zebrar uma ListView e depois de procurar exaustivamente um exemplo que serviu certinho para o que eu queria, e por isso resolvi compartilhar com vocês. é simples e com pouco código, fica muito legal. Tá aÃ:
Private Sub AltLVBackground(lv As ListView, _
ByVal BackColorOne As OLE_COLOR, _
ByVal BackColorTwo As OLE_COLOR)
Dim lSM As Byte
Dim picAlt As PictureBox
With lv
If .View = lvwReport And .ListItems.Count Then
Set picAlt = Me.Controls.Add([Ô]VB.PictureBox[Ô], [Ô]picAlt[Ô])
lSM = .Parent.ScaleMode
.Parent.ScaleMode = vbTwips
.PictureAlignment = lvwTile
lH = .ListItems(1).Height
With picAlt
.BackColor = BackColorOne
.AutoRedraw = True
.Height = lH * 2
.BorderStyle = 0
.Width = 10 * Screen.TwipsPerPixelX
picAlt.Line (0, lH)-(.ScaleWidth, lH * 2), BackColorTwo, BF
Set lv.Picture = .Image
End With
Set picAlt = Nothing
Me.Controls.Remove [Ô]picAlt[Ô]
lv.Parent.ScaleMode = lSM
End If
End With
End Sub
Exemplo:
Para utitilizar: AltLVBackground MyListview, vbWhite, vbRed
Private Sub AltLVBackground(lv As ListView, _
ByVal BackColorOne As OLE_COLOR, _
ByVal BackColorTwo As OLE_COLOR)
Dim lSM As Byte
Dim picAlt As PictureBox
With lv
If .View = lvwReport And .ListItems.Count Then
Set picAlt = Me.Controls.Add([Ô]VB.PictureBox[Ô], [Ô]picAlt[Ô])
lSM = .Parent.ScaleMode
.Parent.ScaleMode = vbTwips
.PictureAlignment = lvwTile
lH = .ListItems(1).Height
With picAlt
.BackColor = BackColorOne
.AutoRedraw = True
.Height = lH * 2
.BorderStyle = 0
.Width = 10 * Screen.TwipsPerPixelX
picAlt.Line (0, lH)-(.ScaleWidth, lH * 2), BackColorTwo, BF
Set lv.Picture = .Image
End With
Set picAlt = Nothing
Me.Controls.Remove [Ô]picAlt[Ô]
lv.Parent.ScaleMode = lSM
End If
End With
End Sub
Exemplo:
Para utitilizar: AltLVBackground MyListview, vbWhite, vbRed
segue este arquivo aqui mesmo do forum,
http://www.vbmania.com.br/pages/index.php?varModulo=Detalhe&varID=7531
e tem este exemplo:
http://www.vbmania.com.br/pages/index.php?varModulo=Detalhe&varID=7531
e tem este exemplo:
procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;
Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
with ListView1.Canvas.Brush do
begin
if (Item.Index mod 2) = 0 then
Color := clYellow
else
Color := clWhite;
end;
end;
James
Esse exemplo aà deve ser em Delphi
Esse exemplo aà deve ser em Delphi
Veja se te ajuda.
http://vbweb.com.br/dicas_visual.asp?Codigo=1786&Classificacao=
[]'s
http://vbweb.com.br/dicas_visual.asp?Codigo=1786&Classificacao=
[]'s
Option Explicit
Private Sub Form_Load()
Me.ListView1.View = lvwReport
Dim FSO As New FileSystemObject
Dim FIL As File
Dim FOL As Folder
Dim ITEM As ListItem
ListView1.ColumnHeaders.Add , , [Ô]Pasta[Ô]
ListView1.ColumnHeaders.Add , , [Ô]Tamanho[Ô]
For Each FOL In FSO.GetDrive([Ô]c:\\[Ô]).RootFolder.SubFolders
Set ITEM = ListView1.ListItems.Add(, , FOL.Name)
ITEM.ListSubItems.Add , , [Ô]Pasta[Ô]
Next
SetColorBar Me.ListView1, Me.Picture1, &HE0E0E0
End Sub
Public Sub SetColorBar(cListView As ListView, cColorBar As PictureBox, Optional lColor1 As Long = &HE2F1E3, Optional lColor2 As Long = vbWhite)
Dim iLineHeight As Long
Dim iBarHeight As Long
Dim lBarWidth As Long
On Error GoTo SetColorBarError
If Not cListView.View = lvwReport Then GoTo SetColorBarError
cColorBar.AutoRedraw = True
cColorBar.BorderStyle = vbBSNone
cColorBar.ScaleMode = vbTwips
cColorBar.Visible = False
cListView.PictureAlignment = lvwTile
cColorBar.Font = cListView.Font
iLineHeight = cColorBar.TextHeight([Ô]|[Ô]) + Screen.TwipsPerPixelY
iBarHeight = iLineHeight * 3
lBarWidth = cListView.Width
cColorBar.Height = iBarHeight * 2
cColorBar.Width = lBarWidth
cColorBar.Line (0, 0)-(lBarWidth, iBarHeight), lColor1, BF
cColorBar.Line (0, iBarHeight)-(lBarWidth, iBarHeight * 2), lColor2, BF
cListView.Picture = cColorBar.Image
Exit Sub
SetColorBarError:
cListView.Picture = LoadPicture([Ô][Ô])
End Sub
Tópico encerrado , respostas não são mais permitidas