How to use ListView anyone plzzzz. . . .
Im using Listview my problem is that i don't know how to get the values in listview i have 5 columns first one qty, unit,pcode,desc and price. I want to get the values of the price in listview and add them. . . . .
can anyone help me with this problem i would be grateful. . . .
Re: How to use ListView anyone plzzzz. . . .
This is a copy of code in one of my programs so it displays data in different columns:
Code:
ListView1.ListItems.Add , , Text1.Text
ListView1.ListItems.SubItems(1) = Text2.Text
ListView1.ListItems.SubItems(2) = Text3.Text
Re: How to use ListView anyone plzzzz. . . .
A short ListView tutorial:
Code:
Option Explicit
Private Sub Form_Load()
With ListView1
.View = lvwReport 'to get rows/cols
.FullRowSelect = True 'optional
.GridLines = True 'optional
.Move 0, 0, ScaleWidth, ScaleHeight
End With
LoadColumnHeaders
LoadData
End Sub
Private Sub Form_Resize()
ListView1.Move 0, 0, ScaleWidth, ScaleHeight
SizeHeaders
End Sub
Private Sub LoadColumnHeaders()
'note this can be done at design time
' by right clicking the LV & selecting properties
Dim i As Long
Dim a() As String
'your column headers
a = Split("Qty,Unit,Pcode,Desc,Price", ",")
For i = 1 To 5
With ListView1.ColumnHeaders.Add
.Text = a(i - 1)
End With
Next
SizeHeaders
End Sub
Private Sub SizeHeaders()
Dim i As Long
For i = 1 To 5 '5 equally sized columns
With ListView1
.ColumnHeaders(i).Width = .Width \ 5 - 60
' the - 60 above prevents the Horiz
' scroll bar from showing
End With
Next
End Sub
Private Sub LoadData()
Dim i As Long
For i = 1 To 50
With ListView1.ListItems.Add
.Text = "Qty " & i ' .Text is Column 1
.SubItems(1) = "Unit " & i 'cols 2-5
.SubItems(2) = "PCode " & i
.SubItems(3) = "Desc " & i
.SubItems(4) = "Price " & i
End With
Next
' Another way
' Dim i As Long
' Dim LI As ListItem
' For i = 1 To 50
' Set LI = ListView1.ListItems.Add(, , "Qty " & i)
' LI.SubItems(1) = "Unit " & i
' LI.SubItems(2) = "PCode " & i
' LI.SubItems(3) = "Desc " & i
' LI.SubItems(4) = "Price " & i
' Next
End Sub
Re: How to use ListView anyone plzzzz. . . .
Here is a link which will be very helpful for you, read and implement it:
http://www.vbforums.com/showthread.php?t=461267
_______________________________________
If I helped you then please help me and rate my post!
Re: How to use ListView anyone plzzzz. . . .
I have 5 columns in listview this are qty,pcode which is product,desc, price and amount. my problem is that when i enter a product twice with the same product desc price and amount and when i click delete it will delete ol the same name i dont understand why but if the name is not the same it will delete it but if they are the same it will delete ol the same name. . . .sometimes i get wrong total amount. . . .this is my code when i delete a product on a listview. . . .
vb Code:
Private Sub cmddelete_Click()
rst.Open "Select * from tblsales", con, adOpenDynamic, adLockOptimistic
While rst.EOF = False
If txttransid = rst!transid And lstlist.SelectedItem.SubItems(1) = rst!pcode Then
rst.Delete
rst.Update
txttot = Val(txttot) - Val(lstlist.SelectedItem.SubItems(4))
cmddelete.Enabled = False
End If
rst.MoveNext
Wend
rst.Close
Call reloadlist
End Sub
Private Sub cmddelete_Click()
rst.Open "Select * from tblsales", con, adOpenDynamic, adLockOptimistic
While rst.EOF = False
If txttransid = rst!transid And lstlist.SelectedItem.SubItems(1) = rst!pcode Then
rst.Delete
rst.Update
txttot = Val(txttot) - Val(lstlist.SelectedItem.SubItems(4))
cmddelete.Enabled = False
End If
rst.MoveNext
Wend
rst.Close
Call reloadlist
End Sub
[B]Function reloadlist()[/B]
rst.Open "Select * from tblsales", con, adOpenDynamic, adLockOptimistic
lstlist.ListItems.clear
While rst.EOF = False
If txttransid = rst!transid Then
lstlist.ListItems.Add , , rst!qty
lstlist.ListItems(lstlist.ListItems.Count).ListSubItems.Add , , rst!pcode
lstlist.ListItems(lstlist.ListItems.Count).ListSubItems.Add , , rst!Desc
lstlist.ListItems(lstlist.ListItems.Count).ListSubItems.Add , , rst!price
lstlist.ListItems(lstlist.ListItems.Count).ListSubItems.Add , , rst!amount
End If
rst.MoveNext
Wend
rst.Close
End Function
Re: How to use ListView anyone plzzzz. . . .
http://www.vbforums.com/attachment.p...id=47243&stc=1
Change the beginning of cmddelete.
Code:
Private Sub cmddelete_Click()
rst.Open "Select * from tblsales", con, adOpenDynamic, adLockOptimistic
Do While rst.EOF = False
If txttransid = rst!transid And lstlist.SelectedItem.SubItems(1) = rst!pcode Then
rst.Delete
rst.Update
txttot = Val(txttot) - Val(lstlist.SelectedItem.SubItems(4))
cmddelete.Enabled = False
Exit Do
End If
rst.MoveNext
Loop
...
Re: How to use ListView anyone plzzzz. . . .
Thank u MartinLiss for helping me. . . .
Last question what is the difference between the while that i put and the Do while exit Do and Loop? cause i don't use that?