Results 1 to 6 of 6

Thread: Subtract column values in listview

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2010
    Posts
    25

    Subtract column values in listview

    Hi, I have a 3 column listview. Column 1 and 2 has few integer. How can I subtract Column 1 and column and show the result in column 3. Below is a sample data for columns.



    Please help me to solve this problem.

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Subtract column values in listview

    You loop through the Items collection of the ListView. For each item, you index the Subitems collection to access each subitem. You get the Text of the first two subitems, convert each one to a number, perform your calculation, convert the result to a String and then assign that to the Text of the third subitem.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2010
    Posts
    25

    Re: Subtract column values in listview

    Hi, thanks for your reply. Can you plz show me code because I am not sure how to loop through the listview items and perform calculation.

    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Subtract column values in listview

    I'm fairly certain that there would be at least one example of looping through the items in a ListView already on the web. Look first, ask questions later.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2010
    Posts
    25

    Re: Subtract column values in listview

    Thanks again for your generosity, I am here having problem with calculating one column from another. I have searched on the net(I always search first) and the kind of problem I am having here not available with working solution. Thats why I asked here.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Subtract column values in listview

    Your problem, like so many people, is that you're looking for code that does exactly what you want. That is often not possible, but that doesn't mean that you can't find relevant examples. Look back at my first post. Do you see how I broke the problem up into steps? It would be quite easy to find example code for each of those steps on the web. You may not find a single example that does all of them but you don't need that. All you need is to determine how to perform each step individually. Once you can do that, it's a simple matter of putting the pieces together.

    So, start at the first step and forget everything else for now.
    You loop through the Items collection of the ListView.
    Show us your code to do just that. As I implied earlier, you should be able to find plenty of examples. What each of those examples actually does inside the loop is not relevant at this stage.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width