Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
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 .

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");
 
Share this answer
 
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
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

}
 
Share this answer
 
v2

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



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