Solved

ListView Tally Dollars

Posted on 2011-09-25
13
282 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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 500 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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