8 Replies - 3278 Views - Last Post: 06 March 2013 - 07:57 AM Rate Topic: ***** 1 Votes

#1 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Find Last Item in Listview and Update the Quantity

Posted 04 March 2013 - 09:57 AM

hello guys,, how do i find the last item in listview is this correct?

if listview1.listitems.item(listview1.listitems.count).text= txtcode.text then
' the code for update the Quantity
' what should i do if the last item in listview has found in how do i update their quantity.
qtyadd = Val(txtqty.Text) + Val(ListView1.SelectedItem.SubItems(2))
subtotaladd = Val(lbltotal.Text) + Val(ListView1.SelectedItem.SubItems(4))
ListView1.SelectedItem.SubItems(2) = qtyadd
ListView1.SelectedItem.SubItems(4) = Format(subtotaladd, "###################.00")
end if


help me guys

Is This A Good Question/Topic? 0
  • +

Replies To: Find Last Item in Listview and Update the Quantity

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Find Last Item in Listview and Update the Quantity

Posted 04 March 2013 - 10:18 AM

This is based on the post you already have open....

As I mentioned in the other thread, the line of code below will reference the last item in the list.

listview1.listitems.item(listview1.listitems.count)


Why do you keep asking if the code is correct?

Does the code run? If not, what error, if any, do you get?

If it does run, what is it doing that is unexpected?

Have you debugged the code, by adding a breakpoint and stepping through it?

This should really be merged with your original post as it's related to that and helps keep everything in one place for future.

This post has been edited by maj3091: 04 March 2013 - 10:36 AM

Was This Post Helpful? 0
  • +
  • -

#3 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Find Last Item in Listview and Update the Quantity

Posted 04 March 2013 - 04:48 PM

View Postmaj3091, on 04 March 2013 - 10:18 AM, said:

This is based on the post you already have open....

As I mentioned in the other thread, the line of code below will reference the last item in the list.

listview1.listitems.item(listview1.listitems.count)


Why do you keep asking if the code is correct?

Does the code run? If not, what error, if any, do you get?

If it does run, what is it doing that is unexpected?

Have you debugged the code, by adding a breakpoint and stepping through it?

This should really be merged with your original post as it's related to that and helps keep everything in one place for future.


i used that code alraedy to find the last item but when i run it, all the item in listview all updated when the last item in listview found.
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Find Last Item in Listview and Update the Quantity

Posted 05 March 2013 - 01:25 AM

If you look at my post in the original thread, I asked why you are using SelectedItem??

You haven't selected the item, so use the same method to reference the last item as you did to find it (i.e.: listview1.listitems.item(listview1.listitems.count))
Was This Post Helpful? 0
  • +
  • -

#5 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Find Last Item in Listview and Update the Quantity

Posted 05 March 2013 - 09:25 AM

View Postmaj3091, on 05 March 2013 - 01:25 AM, said:

If you look at my post in the original thread, I asked why you are using SelectedItem??

You haven't selected the item, so use the same method to reference the last item as you did to find it (i.e.: listview1.listitems.item(listview1.listitems.count))


i use this code to find the last item
if listview1.listitems.item(listview1.listitems.count).text=txtCode.text then

But Still All the Item in Listview if the listitems the same in the Value of txtcode.text should be updated.
Was This Post Helpful? 0
  • +
  • -

#6 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Find Last Item in Listview and Update the Quantity

Posted 05 March 2013 - 11:49 AM

View PostJovel Mark, on 05 March 2013 - 04:25 PM, said:

i use this code to find the last item
if listview1.listitems.item(listview1.listitems.count).text=txtCode.text then

But Still All the Item in Listview if the listitems the same in the Value of txtcode.text should be updated.


I'm sorry, but you've confused me with your last sentence.

If you find a match, are you saying all the same items should be updated or only the last item??

You still didn't answer why you're now using SelectedItem property of the listview?

If you only want to update the last item, then your code should be something like below.

Please note, I haven't tested this code in anyway. It is based on your code in regards to subitems as you have never said what the list columns are. I have only done this as you're either not understanding what I'm trying to tell you, or you're not reading my posts.

' Check if there is anything in the list - Prevent errors
If listview1.listitems.count>0 then
  
  'We have something in the list - Check if the last Item matches what we have entered
  if listview1.listitems.item(listview1.listitems.count).text= txtcode.text then
    
    ' We have a match, so we can update the quantity on the last item (based on your code)
    qtyadd = Val(txtqty.Text) + Val(listview1.listitems.item(listview1.listitems.count).SubItems(2))
    subtotaladd = Val(lbltotal.Text) + Val(listview1.listitems.item(listview1.listitems.count).SubItems(4))
    listview1.listitems.item(listview1.listitems.count).SubItems(2) = qtyadd
    listview1.listitems.item(listview1.listitems.count).SubItems(4) = Format(subtotaladd, "###################.00")

  End If
End If


Was This Post Helpful? 0
  • +
  • -

#7 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Find Last Item in Listview and Update the Quantity

Posted 05 March 2013 - 05:34 PM

View Postmaj3091, on 05 March 2013 - 11:49 AM, said:

View PostJovel Mark, on 05 March 2013 - 04:25 PM, said:

i use this code to find the last item
if listview1.listitems.item(listview1.listitems.count).text=txtCode.text then

But Still All the Item in Listview if the listitems the same in the Value of txtcode.text should be updated.


I'm sorry, but you've confused me with your last sentence.

If you find a match, are you saying all the same items should be updated or only the last item??

if the last item item in listview find olny the last item in listview should updated..

Quote

You still didn't answer why you're now using SelectedItem property of the listview?

base on my Knowledge in VB 6. I used Selected Item in Property Because in My Listview Barcode is the First Column and the Quantity is the 3 Column,
Was This Post Helpful? 0
  • +
  • -

#8 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 303
  • View blog
  • Posts: 1,796
  • Joined: 26-March 09

Re: Find Last Item in Listview and Update the Quantity

Posted 06 March 2013 - 12:59 AM

OK, thanks for clarifying. If you try the code I posted, it might do what you want.

If not, post back as to what it isn't doing correctly.
Was This Post Helpful? 0
  • +
  • -

#9 Jovel Mark  Icon User is offline

  • D.I.C Head

Reputation: -3
  • View blog
  • Posts: 81
  • Joined: 22-November 11

Re: Find Last Item in Listview and Update the Quantity

Posted 06 March 2013 - 07:57 AM

thanks For The HElp Sir. Your Great.. My Problem Solved ...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1