12,448,059 members (73,215 online)
Rate this:
Please Sign up or sign in to vote.
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.

Code block added - OriginalGriff[/edit]
Posted 16-Feb-13 22:04pm
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

Rate this:
Please Sign up or sign in to vote.

## Solution 1

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.
```// 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.
```// 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.
v2
Comments
Member 8054539 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.
Tadit Dash 18-Feb-13 6:39am

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)

Top Experts
Last 24hrsThis month
 ppolymorphe 305 Richard Deeming 185 OriginalGriff 180 Jochen Arndt 175 F-ES Sitecore 120
 OriginalGriff 5,683 Karthik Bangalore 3,335 ppolymorphe 3,262 Maciej Los 2,872 Richard Deeming 2,695

Advertise | Privacy | Mobile
Web02 | 2.8.160811.3 | Last Updated 18 Feb 2013
Copyright © CodeProject, 1999-2016
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