16,004,227 members
0.00/5 (No votes)
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
Comments
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 .

## Solution 2

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

C#
```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

}```

v2

## 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:
C#
```float conservativeSum = 0.0;
float aggresiveSum = 0.0;
for(int i=0; i < Items.Count ; ++i)
{
if(Item[i].IsConservative)
conservativeSum += Item[i].Value;
else
aggresiveSum += Item[i].Value;
}
if(conservativeSum != 100.0)
MessageBox.Show("conservativeSum is not 100");
if(aggresiveSum != 100.0)
MessageBox.Show("aggresiveSum is not 100");```

Comments
sadhana4 27-Jan-13 2:08am
this my datagridview can i use Items.count
Sandeep Mewara 27-Jan-13 2:13am
Yes.
sadhana4 27-Jan-13 2:12am
i have datagridview and three fields
1)AssetsAllocations
2)Asstes
3)Percentages
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

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

Top Experts
Last 24hrsThis month
 Richard Deeming 65 Yvan Rodrigues 40 Pete O'Hanlon 30 Richard MacCutchan 10 OriginalGriff 10
 OriginalGriff 641 Richard Deeming 395 Pete O'Hanlon 300 Dave Kreskowiak 286 CPallini 120

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900