Private Sub getColumnHeaders()
'build the listviews column headers
Dim Header As ColumnHeader
'build header Name
Set Header = ListView1.ColumnHeaders.Add()
Header.Text = "ProductID"
Header.Width = ListView1.Width * 0.28
' width of the header is 29% of the total width of listview1.
' I choose 29%, not 30%, because with 29% the horizontal scrollbar will disappear.
' So in total I use 99% and not 100%
'build header Address
Set Header = ListView1.ColumnHeaders.Add()
Header.Text = "ProductName"
Header.Width = ListView1.Width * 0.4
' width of the header is 40% of the total width of listview1
'build header Telephone
Set Header = ListView1.ColumnHeaders.Add()
Header.Text = "UnitInStock"
Header.Width = ListView1.Width * 0.3
' width of the header is 30% of the total width of listview1
'we have to reset ItemIndex, so there is nothing selected in listview1
ItemIndex = 0
End Sub
'gets the records from the database
'set column header names in the listview properties to Match columns in DB
'To have numbers sorted normally, go to listviw property sorting, check sort, sortkey = 1
Private Sub addToListView()
'End Sub 'end function save
' We use the integer 'a', so we know in which row we are writing (listview)
Dim a As Integer
a = 1
Set rsinventory = helpinghandCon.Execute("SELECT * FROM inventory ORDER BY ProductID", , adCmdText)
' Load the data.
Do While Not rsinventory.EOF
' Set list_item = ListView1.ListItems.Add(, , rsinventory!ProductID) 'column 0
' list_item.SubItems(a) = rsinventory!ProductName 'column 1
' list_item.SubItems(a) = rsinventory!UnitInStock 'column 2
ListView1.ListItems.Add , , rsinventory!ProductID
ListView1.ListItems(a).ListSubItems.Add , , rsinventory!ProductName
ListView1.ListItems(a).ListSubItems.Add , , rsinventory!UnitInStock
' We must know which row contains the data from which row from the table People.
' Therefore we copy the ID from the table to the Tag of the row which contains
' the data from that row in the table. Sorry if this sounds complicated,
' but I'm not that good in teaching LOL :-)
ListView1.ListItems(a).Tag = rsinventory!ProductID
' Increase 'a'
a = a + 1
' Move to the next row in the recordset
rsinventory.MoveNext
' Do the same stuff again, until we reached the End Of File
Loop
' Close the recordset and connection.
'rsinventory.Close
'helpinghandCon.Close
End Sub
'when the submit button is clicked, all checked items are saved
Private Sub save()
Dim a As Integer
Dim id As Integer
a = 1
If ItemIndex <> 0 Then
rsinventory.Index = "ProductID"
rsinventory.MoveFirst
rsinventory.Seek "=", ListView1.ListItems.item(ItemIndex).Tag
'we reset itemindex to 0, this means that nothing is selected in listview1
ItemIndex = 0
Else
Const SQLInc = "UPDATE inventory SET UnitInStock = UnitInStock + 100 "
Const SQLDec = "UPDATE DaTable SET DaColumn = DaColumn - 1 "
Dim lstYourItem As ListItem
Dim strTemp As String
strTemp = ""
For Each lstYourItem In ListView1.ListItems
If lstYourItem.Checked Then strTemp = strTemp & "," & lstYourItem.Tag
id = ListView1.ListItems(a).Tag
Next
strTemp = SQLInc & "WHERE [B]?????[/B] IN (" & Mid(strTemp, 2) & ") " 'Mid removes leading comma
helpinghandCon.Execute strTemp
End If
End Sub