Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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
Comments
jibesh at 27-Jan-13 0:25am
   
how did you add the items to the gridviewitem?
sadhana4 at 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
good
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)
{
  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");
  Permalink  
Comments
sadhana4 at 27-Jan-13 2:08am
   
this my datagridview can i use Items.count
Sandeep Mewara at 27-Jan-13 2:13am
   
Yes.
sadhana4 at 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 at 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 at 4-Feb-13 6:11am
   
Conservative or Aggressive are dynamaic so how can i do ??
plz tell
Rate this: bad
good
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
 
}
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 878
1 OriginalGriff 410
2 CPallini 275
3 George Jonsson 226
4 Richard Deeming 145
0 OriginalGriff 5,450
1 CPallini 4,500
2 Sergey Alexandrovich Kryukov 4,482
3 George Jonsson 3,057
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 27 Jan 2013
Copyright © CodeProject, 1999-2014
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