Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i run as follows in datagridview in windows applciation


Course    GS        VB    SJ     RK      MS(faculty)      Total


 REO                                                        10
 AFF                                                        10




total number of faculty is 5
total hours of course is 10

when i divide the total(10) by number of faculty (5) and give the answer 2.

i want to display the 2 for each faculty GS,VB,SJ,RK,Ms.

i want the output as follows;

i have one Load Button

Course    GS        VB    SJ     RK      MS(faculty)      Total

 REO      2         2     2       2      2                 10
 AFF      2         2     2       2      2                 10



when click the Load button 2 has to displayed in datagridview for each faculty.

for that i have using this formula, total (10) is divide by number of faculty(5) gives the answer 2

this 2 will display in datagridview for each faculty.

for th above output how can i do using csharp.

Note: it is a windows application

please help me.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 16-Feb-13 22:18pm
v2
Comments
OriginalGriff 17-Feb-13 4:19am    
Where is your data coming from?
How do you get it into the DataGridView at the moment

1 solution

Logic can be as follows...

1. On Load button click, Loop through all the rows of DataGridView using foreach statement like below...

For Each row, inside the loop do the following.

2. Find the Total column value for the row.

3. Apply logic "Total/No._Of_Faculties" and find the result.

4. Find all the Columns related to Faculties and assign this value to them.

For looping code will look like below.
C#
// Write this inside the load button click event.
foreach(DataGridViewRow row in dgvCourses.Rows)
{
     // Do task for each row using "row".
}


Update
Code may be like below.
C#
// Write this inside the load button click event.
int totalHours = 0;
int facultyHour = 0;

foreach(DataGridViewRow row in dgvCourses.Rows)
{
     // Do task for each row using "row".
     totalHours = Convert.ToInt32(row.Cells["total"].Value); // Here "total" is the column name.
     
     facultyHour = totalHours /  5 ;

     // Assign this value to the below cells.
     //GS        VB    SJ     RK      MS
     row.Cells["GS"].Value = facultyHour.ToString(); 
     row.Cells["VB"].Value = facultyHour.ToString(); 
     row.Cells["SJ"].Value = facultyHour.ToString(); 
     row.Cells["RK"].Value = facultyHour.ToString(); 
     row.Cells["MS"].Value = facultyHour.ToString(); 
}


NOTE
Replace the Cell names in the code correctly.
I have not tested this code. So, just debug and see what is happening. But follow this logic.
 
Share this answer
 
v2
Comments
[no name] 17-Feb-13 20:31pm    
you said the above answer ok.

but i am new to one applying loop for each.

kindly please tell me how can i do?

please send the code and help me.
Please check the answer under heading "Update".

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