Solved

ListView Tally Dollars

Posted on 2011-09-25
13
273 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
 
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now