如何将total和dislay拆分为datagridview [英] how to split the total and dislay into datagridview

查看:74
本文介绍了如何将total和dislay拆分为datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在windows applciation中的datagridview中运行如下





when i run as follows in datagridview in windows applciation


Course    GS        VB    SJ     RK      MS(faculty)      Total


 REO                                                        10
 AFF                                                        10









教职员工总数是5

总课时数当然是10



当我将总数(10)除以教师人数(5)并给出答案2.



i想要为每个教师GS展示2 ,VB,SJ,RK,Ms。



i想要输出如下;



i有一个加载按钮







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



<单击加载按钮2必须在datagridview中为每个教师显示。



我有的使用这个公式,总数(10)除以教师数量(5)给出答案2



这个2将显示在每个教员的datagridview中。



以上输出如何使用csharp。



注意:它是一个Windows应用程序



请帮帮我。



[edit]已添加代码块 - OriginalGriff [/ edit]




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]

推荐答案

逻辑可以如下...



1.点击加载按钮,循环显示所有t他的DataGridView行使用 foreach 语句如下...



For Each row,in the within循环执行以下操作。



2.找到该行的总列值。



3.应用逻辑Total / No._Of_Faculties并找到结果。



4.找到与Faculties相关的所有列并将其赋值给它们。



循环代码如下所示。

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.


这篇关于如何将total和dislay拆分为datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆