CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2013
    Posts
    34

    ListView Problem without saving in DB Acces Using VB 6.0

    Hello Guys.. I have a Code For Saving Item in ListView But My Problem is What If My First Column Same BarCode into Example:
    Barcode QTY
    001 5

    And I add Another Item

    Barcode QTY
    001 5
    001 5

    My Point is What Should I do And How to Do The Quantity of two Itme Added in One Then They BEcome
    Barcode QTY
    001 10


    This is My Code for Adding in Listview
    Code:
    ListView1.ListItems.Add , , lblrp.Caption
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , MDIForm1.lbldate.Caption
    Help me Guys
    Thanks in Advance

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    You should probably check to see if the item is already in the list before you add it and if it is in the list update the qty of the one that is already there rather than adding another one.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    In My Mind What if Customer Buy 3 Items of My Clothes then I forget to Enter the Qty into 3 , then I want ti enter Again the Barcode to Added the Another One, Then The Value of the One Item is Automatically Updated If There is Already Item in list..

  4. #4
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    this is my Code..
    What Should I Do? Doesnt Work
    Code:
    If txtCode.Text = ListView1.SelectedItem.ListSubItems.Add Then
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
    Else
    ListView1.ListItems.Add , , lblrp.Caption
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtProductName.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtQty.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtPrice.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , MDIForm1.lbldate.Caption
    End If

  5. #5
    Join Date
    Jul 2005
    Posts
    1,083

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    To check if the code is already in the listview you should iterate all the listview's rows
    JG


    ... If your problem is fixed don't forget to mark your threads as resolved using the Thread Tools menu ...

  6. #6
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    Quote Originally Posted by jggtz View Post
    To check if the code is already in the listview you should iterate all the listview's rows
    How To iterate all the listview's rows What Should I do?

  7. #7
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    You would use a loop and check each item. If you find the item then update the qty on that subitem and exit the loop

    If no match was found then and only then would you use the .additem method to add a new item to the list.
    Always use [code][/code] tags when posting code.

  8. #8
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    Quote Originally Posted by DataMiser View Post
    You would use a loop and check each item. If you find the item then update the qty on that subitem and exit the loop

    If no match was found then and only then would you use the .additem method to add a new item to the list.
    Sir It possible use the loop in listview? I am Saving Item in ListView Without Saving in DB,..

    I Actually know to use loop if my item automatically Save in Db, But in My Problem, no I dont know how to loop the item in Listview because The Item was save in Listview not Saving in Db ..

    Sir Any Idea how to loop the item in listview?

    Thanks Sir..

  9. #9
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    Hello Sir.. I am Using FindItem to Find item in listview but i dont how to Add the Qty of the same item in one..
    Code:
    Dim itm As MSComctlLib.ListItem
    
        Set itm = ListView1.FindItem(txtCode.Text, lvwSubItem)
        'for partial search use this:
        '''Set itm = ListView1.FindItem("partial text goes here", lvwSubItem, , lvwPartial)
        If Not itm Is Nothing Then
            itm.EnsureVisible
            itm.Selected = True
            MsgBox "Found"
    Else
    
    ListView1.ListItems.Add , , lblrp.Caption
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , MDIForm1.lbldate.Caption
    End If

  10. #10
    Join Date
    Feb 2013
    Posts
    34

    Re: ListView Problem without saving in DB Acces Using VB 6.0

    Quote Originally Posted by jggtz View Post
    To check if the code is already in the listview you should iterate all the listview's rows
    sir thanks for the idea..
    this is my code and run perfectly i am happy so much thank
    Code:
    Dim qtyadd As String
    Dim subtotaladd As String
    Dim itm As MSComctlLib.ListItem
    Dim i As Integer
    
    
        Set itm = ListView1.FindItem(txtCode.Text, lvwSubItem)
         If Not itm Is Nothing Then
            itm.EnsureVisible
            itm.Selected = True
            MsgBox "Found"
            
       qtyadd = Val(txtqty.Text) + Val(ListView1.SelectedItem.SubItems(3))
       subtotaladd = Val(lbltotal.Text) + Val(ListView1.SelectedItem.SubItems(5))
        ListView1.SelectedItem.SubItems(3) = qtyadd
        ListView1.SelectedItem.SubItems(5) = Format(subtotaladd, "###################.00")
    Else
    ListView1.ListItems.Add , , lblrp.Caption
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtCode.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtproductname.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtqty.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , txtprice.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , lbltotal.Text
    ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , MDIForm1.lbldate.Caption
    
    End If

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured