How to populate a VB 6.0 ListView (WORKING SAMPLE)

For who may interest, this a piece of code I made that populates a VB 6.0 ListView object from .

http://img3.imageshack.us/img3/9480/notesandlistviewsamplelg6.png

This ListView is populated by running a categorized view with a NotesViewNavigator object.

It is easy to start from here and adapt the code to your needs. It took me a while to make it works but finally I succeded.

It works in my Windows XP and Office 2003.

Note: To insert the ListView Object, follow the Create / Object menu, select Control and look for Microsoft ListView Control, Version 6.0

In the properties of the object, set the name for the one you will use in the code (in my sample is “llista”)

-----------------CODE

%REM

  here we prepare the Headers

%END REM

Sub Postopen(Source As Notesuidocument)

Dim ws As New notesuiworkspace

Dim vista As NotesView

Dim control As Variant

Dim lwItem As Variant

Dim xlCenter  As Variant



xlCenter = 1



' Get the handle to the object

Set control = source.getObject("llista")

With control

	.gridlines = True

	.hidecolumnheaders = False

End With



' Set the first column Header text

Call control.ColumnHeaders.Add(,"technician","Technician")



' Set the 31 columns for days in a month

For i = 1 To 31

	columnname$="A" + Trim(Str(i))

	columntitle$ = Trim(Str(i))

	Call control.ColumnHeaders.Add(,columname$ , columntitle$, 24 , xlCenter)

Next

End Sub

%REM

  here we populate the listview

%END REM

Sub Click(Source As Button)

Dim ws As New notesuiworkspace

Dim db As NotesDatabase

Dim vista As NotesView

Dim control As Variant

Dim lwItem As Variant

Dim vnav As NotesViewNavigator

Dim entry As NotesViewEntry

Dim clau As String

Dim uidoc As NotesUIDocument



Dim vbRed As Variant

Dim vbBlue As Variant

Dim vbCyan As Variant



vbRed = 255

vbBlue = 16711680

vbCyan= 16776960



' let's prepare a key for fetching the documents to be populated

Set uidoc = ws.CurrentDocument

clau = uidoc.FieldGetText("SelectedYear") + "|" + uidoc.FieldGetText("SelectedMonth")



'Get the handle to the object

Set control = uidoc.getObject("llista")

' lets clear the listview

Call control.ListItems.clear



Set db = ws.CurrentDatabase.Database

Set vista = db.GetView("Booked")

Set vnav = vista.CreateViewNavFromCategory( clau )

Set entry = vnav.GetFirst()

While Not(entry Is Nothing)

	If entry.IsCategory Then

		REM This is a Technician

		' populating the first column line

		Set lwItem = control.ListItems.add(,,entry.ColumnValues(1))			

	Else

	'Set busy Day with corresponding set up

		Forall dias In entry.Document.dates

			With lwitem

				' let's paint the day that the technician is busy

				i = Day(dias)

				.subitems(i) = "o"

				.listsubitems(i).Bold = True

				

				' colours depending of the Technician status

				Select Case entry.Document.form(0)

				Case "ILLNESS" : .listsubitems(i).ForeColor = vbCyan

				Case "HOLIDAYS" : .listsubitems(i).ForeColor = vbBlue

				Case "ONCALL" : .listsubitems(i).ForeColor = vbRed

				End Select

				

			End With

			

		End Forall

	End If

	Set entry = vnav.GetNext(entry)

Wend



'Refresh the control

Call control.refresh()

End Sub

-----------------END OF CODE

I hope it will be useful out there!

Best Regards

Subject: -

Subject: RE: It’s too bad LotusScript can’t respond to the events. That would really be helpful.

yep, but at least you can use this to show tabular data instead of using a view.It is pretty fast to refresh it

Is the most similar thing to having a dynamic table in Lotus Notes.

Subject: How to populate a VB 6.0 ListView (WORKING SAMPLE)

This is amazing. Thanks for posting the code. I have implemented the control and have added LS code to sort the columns in the columnclick event.

Also I can open the notes document by storing the UNID in a hidden column and using the itemclick event to open the document.