Transfer the data to another listview
Hi,
I am creating project in Visual basic where i need to transfer some selected items from one list view to another list view. When i double click on any item , an input box should get appear which should ask me for quantity which should be less then existing one. After clicking on OK button lesser quantity should display on other list view it computes the total amount of the price of the quantity. Can anyone help me out with this issue following is the code for my first view list.
Code:
Public Sub list()
Dim lst1 as List_Item
Dim x1 As Integer
ListView1.List_Items.clear
While Not rs.EOF
Set lst = ListView1.List_Items.Add(, , rs(0))
For x = 1 To 4
lst.SubItems(x) = rs(x)
Next x
rs.MoveNext
Wend
End Sub
Re: Transfer the data to another listview
Try to use below code and i am sure this would transfer data to another view list whose name as List_view2.
Code:
Private Sub ListView1_DblClick()
Dim lst2 As List_Item
Dim ip1 As String
ip1 = InputBox("Enter the quantity to be lessen", "Quantity")
With List_View1.SelectedItem
.SubItems(3) = (.SubItems(3)) - Val(ip1)
Set lst2 = List_View2.ListItems.Add(, , List_View1.SelectedItem)
lst2.SubItems(1) = .SubItems(1)
lst2.SubItems(2) = .SubItems(2)
lst2.SubItems(3) = ip1
lst2.SubItems(4) = (Val(ip1)) * (.SubItems(4))
End With
End Sub
Transfer the data to another listview
Thank you Ektaa for replying me, it's working great, but over here I'm facing one more issue when i try to input greater amount of quantity it makes negative number on stocks. Can anyone tell me how can i make total all the value of price and if any stock has zero quantity then i should not be able to input values over there.
Re: Transfer the data to another listview
If you want to have a code which if the stock is zero then it cannot input quantity and also how can you total all the value of price, then try to add following code
Stock Quantity is Zero:
Code:
If List_view1.SelectedItem.SubItems(3) = 0 Then
Msgbox "Stock Not Available"
Exit Sub
End If
Input is Greater than the Stock Quantity:
Code:
If Val(ip1) > List_view1.SelectedItem.SubItems(3) Then
Msgbox "Input value is greater then stock quantity"
Exit Sub
End If
For Total Price:
Code:
Dim j as Integer
Dim Total_Price as Currency
For j = 1 to Listview1.List_Items.Count
Total_Price = Total_Price + Val(Listview1.List_Items(i).SubItems(4).Text)
DoEvents
Next i
Msgbox Total_Price