Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C# ListView questions.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
zaczac
Master Cheater
Reputation: 0

Joined: 01 May 2007
Posts: 266
Location: Ontario, Canada

PostPosted: Tue Dec 06, 2011 10:10 pm    Post subject: C# ListView questions. Reply with quote

Just wanted to know how I would go about taking multiple values in a ListView and performing a calculation with them. Right now the ListView accepts up to 40 rows of data from the user.. each row contains a value for "hours" and "grade. I need to multiply the hours by grade for each row then divide that number by the total amount of rows filled. Heres a small example.

Subject____Hours___Grade

MATH_____11______4
COMM____11______4.5
DBAS_____9_______3
GNED_____8 _______5

If those are the values in the ListView I would need to do the calculation for those + each time a new row is added the final result is updated.

11 x 4 = 44
11 x 4.5 = 49.5
9 x 3 = 81
8 x 5 = 40

total points = 214.5

final result = total points / number of rows
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 07, 2011 9:15 am    Post subject: Reply with quote

Two ways I can think of are either:

1. Sum up the items manually when you add each new item. You can loop the items in the ListView and obtain each columns value from the SubItem property.

2. Create your own custom ListView control that will expose an OnItemAdded event to allow you to update only when needed and such.

Btw 9 x 3 = 81 isn't correct Razz

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
zaczac
Master Cheater
Reputation: 0

Joined: 01 May 2007
Posts: 266
Location: Ontario, Canada

PostPosted: Wed Dec 07, 2011 11:51 am    Post subject: Reply with quote

How would I go about multiplying the hours and GPA columns together for each row... Could you show me an example (code) what it would look like.


Capture.PNG
 Description:
 Filesize:  10.95 KB
 Viewed:  8639 Time(s)

Capture.PNG


Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 07, 2011 1:38 pm    Post subject: This post has 1 review(s) Reply with quote

Lets say your ListView is named listView1. You can loop each item using:

Code:

foreach(ListViewItem lvi in listView1.Items)
{
    double dblResult = double.Parse(lvi.SubItems[1].Text) * double.Parse(lvi.SubItems[3].Text);
    // Do what you need with dblResult..
}


The subitems for each entry start at index 0 (subject name) and so on.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
zaczac
Master Cheater
Reputation: 0

Joined: 01 May 2007
Posts: 266
Location: Ontario, Canada

PostPosted: Wed Dec 07, 2011 2:34 pm    Post subject: Reply with quote

Alright that worked but the first value is always 0...

^^ Fixed that ^^

Now I need to limit the amount of items in the viewlist to 40.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Dec 07, 2011 4:46 pm    Post subject: Reply with quote

Inside your 'Add' button call at the top, check if the listView1.Items.Count == 40, if it is just exit the function.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
zaczac
Master Cheater
Reputation: 0

Joined: 01 May 2007
Posts: 266
Location: Ontario, Canada

PostPosted: Wed Dec 07, 2011 5:33 pm    Post subject: Reply with quote

Solved all the problems, Thanks a ton wiccaan
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites