Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ListView Tally Dollars

Posted on 2011-09-25
13
Medium Priority
?
283 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

721 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