ListView Satırı Renklendirme - ListView Row BackColor

Listeleme kutusu. Verileriniz klasör ve dosyalarınızı görsel olarak kontrol edebileceğiniz bir nesne modeli.

ListView Satırı Renklendirme - ListView Row BackColor

İleti#1)  Murat OSMA » 02 Nis 2012 17:06

ListView'de satır renklendirme ile ilgili örnek dosya ek'tedir..

Form Görüntüsü
ListView Satır Renklendirme.PNG

Kod: Tümünü seç
'UserForm kodları
Option Explicit
Private Declare Function SetWindowLong& Lib "user32" Alias _
"SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long _
, ByVal wCmd As Long) As Long
Private Const GWL_WNDPROC As Long = (-4&)
Private hWnd As Long

Private Sub UserForm_Initialize()
Dim i&
hWnd = GetWindow(FindWindow(vbNullString, Me.Caption), 5)
With Me.ListView1
.View = lvwReport
.FullRowSelect = True
.ColumnHeaders.Add , , "Kolon 1", .Width * 1 / 3
.ColumnHeaders.Add , , "Kolon 2", .Width * 1 / 3
.ColumnHeaders.Add , , "Kolon 3", .Width * 1 / 3
For i = 0 To 24
With .ListItems.Add(, , "Ders: " & Format(i, "00"))
.SubItems(1) = "Excel"
.SubItems(2) = "VBA.Net"
End With
Next
End With
OldProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
Call SetWindowLong(hWnd, GWL_WNDPROC, OldProc)
End Sub

'Module Kodları
Option Explicit
Private Const NM_CUSTOMDRAW = (-12&)
Private Const WM_NOTIFY As Long = &H4E&
Private Const CDDS_PREPAINT As Long = &H1&
Private Const CDRF_NOTIFYITEMDRAW As Long = &H20&
Private Const CDDS_ITEM As Long = &H10000
Private Const CDDS_ITEMPREPAINT As Long = CDDS_ITEM Or CDDS_PREPAINT
Private Const CDRF_NEWFONT As Long = &H2&
Private Type NMHDR
hWndFrom As Long
idFrom As Long
code As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Type NMCUSTOMDRAW
hdr As NMHDR
dwDrawStage As Long
hDC As Long
rc As RECT
dwItemSpec As Long
uItemState As Long
lItemlParam As Long
End Type

Private Type NMLVCUSTOMDRAW
NMCW As NMCUSTOMDRAW
ForeColorText As Long
BackColorText As Long
End Type

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpDest As Any, lpSource As Any, ByVal cBytes&)
Declare Function CallWindowProc& Lib "user32" Alias _
"CallWindowProcA" (ByVal lpPrevWndFunc&, ByVal hWnd&, _
ByVal Msg&, ByVal wParam&, ByVal lParam&)
Public OldProc As Long

Function WindowProc(ByVal hWnd As Long, ByVal iMsg As Long _
, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_NOTIFY
Dim UDT_NMHDR As NMHDR
CopyMemory UDT_NMHDR, ByVal lParam, 12&
With UDT_NMHDR
If .code = NM_CUSTOMDRAW Then
Dim UDT_NMLVCUSTOMDRAW As NMLVCUSTOMDRAW
CopyMemory UDT_NMLVCUSTOMDRAW, ByVal lParam, Len(UDT_NMLVCUSTOMDRAW)
With UDT_NMLVCUSTOMDRAW.NMCW
Select Case .dwDrawStage
Case CDDS_PREPAINT
WindowProc = CDRF_NOTIFYITEMDRAW
Exit Function
Case CDDS_ITEMPREPAINT

If (.dwItemSpec Mod 2) = 0 Then
UDT_NMLVCUSTOMDRAW.ForeColorText = vbRed
UDT_NMLVCUSTOMDRAW.BackColorText = &HC0C0C0
CopyMemory ByVal lParam, UDT_NMLVCUSTOMDRAW, Len(UDT_NMLVCUSTOMDRAW)
End If

WindowProc = CDRF_NEWFONT
Exit Function
End Select
End With
End If
End With
End Select
WindowProc = CallWindowProc(OldProc, hWnd, iMsg, wParam, lParam)
End Function

Sub CustomListView()
UserForm1.Show
End Sub
Bu iletideki ekleri görmek için gerekli yetkilere sahip değilsiniz.


Son güncel tutan Murat OSMA, 02 Nis 2012 17:06.
Kullanıcı avatarı
Murat OSMA
Site Forum Yöneticisi
 
Adı Soyadı:Murat OSMA
Kayıt: 05 Arl 2008 00:34
Konum: İstanbul
Meslek: Excel & VBA Eğitmeni
Yaş: 33
İleti: 14305
 
Cinsiyet: Bay
Bulunduğunuz İl / Semt: Bağcılar - İSTANBUL

Forum ListView

Online Kullanıcılar

Bu forumu görüntüleyenler: Kayıtlı kullanıcı yok ve 1 misafir

cron
Bumerang - Yazarkafe