=== Module ===
Public Cn as new Connection
Public Record as New Recordset
Public OnBegin as Boolean
Public Rs as new namaclassnya 'declarasi untuk load class yg dibuat
Private Declare Sub InitCommonControls Lib "comctl32.dll" () 'declarasi file ocx
Function OpenKoneksi() as Boolean
On error goto Bingung
set Cn as new ADODB.Connection
cnn.open "Provider=MSDASQL.1;Persist Security Info=False;Data Source='namakoneksinya'"
openkoneksi=true
exit function
Bingung:
OpenKoneksi=false
msgbox err.description & " " & err.number
end Function
Sub Main()
InitCommonControls ' untuk membuat tampilan button dll menjadi XP style pake Manifest
mainmenu.show 'Nama Form Utama
End Sub
Sub Loading(Pesan, Muncul as boolean)
doevents
frmPesan.msg.caption=Pesan
if muncul then
doevents
frmpesan.show 0,Mainmenu
doevents
else
unload frmpesan
end if
end sub
===== Class Module ====================
'untuk recordsetnya
Function OpenRecord(strSQL As String, Optional CursorLocation As Byte = 3, Optional CursorType As Byte = 3, Optional LockType As Byte = 1) As Boolean
On Error GoTo Failed
Set Record = Nothing
Set Record = New ADODB.Recordset
With Record
.CursorLocation = CursorLocation
.Open strSQL, Cnn, CursorType, LockType
End With
OpenRecord = True
Exit Function
Failed:
OpenRecord= False
End Function
'untuk looping data di Listview
Public Sub FillListView(ByRef sListView As ListView, ByRef sRecordSource As Recordset, ByVal sNumOfFields As Byte, ByVal with_num As Boolean, ByVal show_first_rec As Boolean)
Dim x As Variant
Dim i As Byte
On Error Resume Next
sListView.ListItems.Clear
If sRecordSource.RecordCount < 1 Then Exit Sub
sRecordSource.MoveFirst
Do While Not sRecordSource.EOF
Set x = sListView.ListItems.Add(, , "" & sRecordSource.Fields(0))
For i = 1 To sNumOfFields - 1
If show_first_rec = True Then
If with_num = True Then
If sRecordSource.Fields(CInt(i) - 1).Type = adDouble Then
x.SubItems(i) = FormatRS(sRecordSource.Fields(CInt(i) - 0))
Else
x.SubItems(i) = "" & FormatRS(sRecordSource.Fields(CInt(i) - 0))
End If
Else
If sRecordSource.Fields(CInt(i)).Type = adDouble Or sRecordSource.Fields(CInt(i)).Type = adDate Then
x.SubItems(i) = FormatRS(sRecordSource.Fields(CInt(i)))
Else
x.SubItems(i) = "" & FormatRS(sRecordSource.Fields(CInt(i)))
End If
End If
Else
x.SubItems(i) = "" & FormatRS(sRecordSource.Fields(CInt(i) + 1))
End If
Next i
sRecordSource.MoveNext
Loop
i = 0
Set x = Nothing
End Sub
'Cara pake di Form
' Form
' Listview
'Misalkan di form sudah dibuat dengan Listview column sebagai berikut
Private Sub Form_load()
lv.listitems.clear
lv.columnheader.add,,"No",400
lv.columnheader.add,,"Nama",1800
lv.columnheader.add,,"Keterangan",3000 ' dan seterusnya sebenarnya ini juga bisa di masukkan di class.
Rs.OpenRecord "Select * from nama table where status<>1"
if not record.eof then
Rs.FillListview lv,record,3,true,true ' 3 adalah jumlah column yg akan ditampilkan.
end if
end sub
Coba dech biat yg suka coding pake listview gak pake coding cara lama
untuk typelock saya pake OpenStatis dan Cursortypenya readonly supaya untuk load data yg besar cepat.
kekurangan dari coding listview diatas belum pake Paging Database. mungkin lain kali akan saya post untuk yg paging databaes methodnya.
thanks
Eko Budi Susilo
