Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ListView Tally Dollars

Posted on 2011-09-25
13
Medium Priority
?
286 Views
Last Modified: 2012-06-21
I would like to automate this so it will calculate once the list is generated. I don't want the user to have to click on anything, I found this but can't seem to tweak it to be automatic.

Dim indexes As ListView.SelectedIndexCollection = _
        Me.ListView1.SelectedIndices
    Dim index As Integer
    Dim price As Double = 0.0
    For Each index In indexes
        price += Double.Parse(Me.ListView1.Items(index).SubItems(1).Text)
    Next

    ' Output the price to TextBox1.
    TextBox1.Text = CType(price, String)

Open in new window

0
Comment
Question by:Jack_Jones
  • 8
  • 5
13 Comments
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36598047
Anyone Alive?
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36598645
You could put a timer on your form that will fire when anything in the listview index changes.
Perhaps in a click event or in your item click or itemcheck events.

put about 100 on the timer, disable it when it starts and run your code above in the timer.

0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36600528
would I just copy and paste that into a timer, right now it generates 0 in the textbox
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36600578
The more I look at the solution I gave the more I realize I had not  had coffee when I typed it.
A timer would be useless (unless) it ran on it's own and ran constantly which could cause a drain on you.

If you could put the above code in an event of your listview that fired when a value changed then you would be fine.  Otherwise - if there are no events that would help you like the ones I mentioned then a timer may work instead.

0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 2000 total points
ID: 36600584
Would help if I put the code with this :) - need more coffee
' NO TIMER
Private sub ListView_ItemClick()
    Dim indexes As ListView.SelectedIndexCollection = Me.ListView1.SelectedIndices
    Dim index As Integer
    Dim price As Double = 0.0
    For Each index In indexes
        price += Double.Parse(Me.ListView1.Items(index).SubItems(1).Text)
    Next

    ' Output the price to TextBox1.
    TextBox1.Text = CType(price, String)

End Sub

' WITH TIMER
' set timer INTERVAL property to something you can tolerate where 1000 = 1 second
Private Sub tmrCalcME_Timer()
    
    Dim indexes As ListView.SelectedIndexCollection = Me.ListView1.SelectedIndices
    Dim index As Integer
    Dim price As Double = 0.0
    For Each index In indexes
        price += Double.Parse(Me.ListView1.Items(index).SubItems(1).Text)
    Next

    ' Output the price to TextBox1.
    TextBox1.Text = CType(price, String)
End Sub

Open in new window

0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36600832
For some reason it just don't generate anything into the textbox, I have the correct sub and listview entered. Just weird, is it possible to just open a file read it all and then calculate the values from it, that would be easier for me lol.
0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36600894
Perhaps the event is not working - did you try the timer method ?
make sure the timer is enabled and an interval entered
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36601006
well got my cup of joe kicked in, got it to load the timer but only gives a value of 0 as a result, the subitem should be 4 according to the colums that I set in ListView2 box.
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36601058
So did some tweaking and got it to generate a dollar amount, however I don't want the user to have to click anything to generate the info, is there a small code I can put to tell vb to auto select the first row of data?


The following code works to generate the info, but wanted it to be automated so user don't have to click.
 Dim indexes As ListView.SelectedIndexCollection = Me.ListView2.SelectedIndices
        Dim index As Integer
        Dim price As Double = 0.0
        For Each index In indexes
            price += Double.Parse(Me.ListView2.Items(index:=4).Text)
        Next

        ' Output the price to TextBox1.
        vehrtlprice.Text = CType(price, String)

Open in new window

0
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 36601653
Have you tried the timer ?
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36601741
Yep the timer works, but only when you click an item in the ListView2 control, just want it to auto generate without the user having to click on the listview item.
0
 
LVL 1

Author Comment

by:Jack_Jones
ID: 36602107
Finally got it figured out, will give you props for the timer idea that I didn't even thing of.

ListView2.Items(0).Selected = True
        ListView2.Select()

Open in new window

0
 
LVL 1

Author Closing Comment

by:Jack_Jones
ID: 36602112
The key was having a timer, and then i finally found out how to auto select it.


ListView2.Items(0).Selected = True
        ListView2.Select()

Open in new window

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question