Click here to Skip to main content
12,954,522 members (55,747 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Assets Allocations Assets Percentage
Conservative eqity 10
Conservative debt 10
Conservative cash 30
Conservative commodities 10
Conservative gold 10
Conservative Liqiud 30
Aggressive eqity 10
Aggressive debt 10
Aggressive cash 40
Aggressive commodities 10
Aggressive gold 10
Aggressive Liqiud 20

i want show the Messgebox if total Percentage is not equal to 100
so i dont know how to check through Loop for Conservative and Aggressive percentages .plz can you tell how i can check throught loop and show messagebox .
using C# in the windows applications
thanks in advance
Posted 26-Jan-13 17:25pm
jibesh 27-Jan-13 0:25am
how did you add the items to the gridviewitem?
sadhana4 27-Jan-13 2:21am
i made view for that 3 fields and than i defined the method in the clientbl
return datatable .i bind view in the datatable .
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

i dont know how to check through Loop for Conservative and Aggressive percentage
Where ever you are getting this data, maintain a flag for each entry if it is a Conservative type or Aggresive type. Post this, all you have to do is loop through all the items and based on the flag have two counters to have sum of each type. At the end of loop, check the counters for sum to be 100. In case not, raise the message in a message box.

Something like:
float conservativeSum = 0.0;
float aggresiveSum = 0.0;
for(int i=0; i < Items.Count ; ++i)
    conservativeSum += Item[i].Value;
     aggresiveSum += Item[i].Value; 
if(conservativeSum != 100.0)
  MessageBox.Show("conservativeSum is not 100");
if(aggresiveSum != 100.0)
  MessageBox.Show("aggresiveSum is not 100");
sadhana4 27-Jan-13 2:08am
this my datagridview can i use Items.count
Sandeep Mewara 27-Jan-13 2:13am
sadhana4 27-Jan-13 2:12am
i have datagridview and three fields
means Item[i].values can i get percentage(values(10,20,30,40)) for checking 100 or not
Sandeep Mewara 27-Jan-13 2:14am
I shared the full logic and pseudo code. Please try!

Items[i].Values is for example. You need to write your substitute code that will get the values.
sadhana4 4-Feb-13 6:11am
Conservative or Aggressive are dynamaic so how can i do ??
plz tell
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

DataGridview has a property called Rows which is a collection of DataGridViewRows you can iterate through the datagridview as shows below.

foreach(DataGridViewRow row in datagridview.Rows)
   string columnvalue = row.Cells["ColumnsName_AssetAllocation].ToString();//you can also use the column Index
   //add your logic here as explained by Sandeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,539
CHill60 3,490
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100