如何根据虚拟列值将公式放在datagridview列上 [英] How to put formula on datagridview column based on virtual column values

查看:71
本文介绍了如何根据虚拟列值将公式放在datagridview列上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算百分比并在datagridview(未绑定)百分比列中显示

但我想从查询中的表中选择的虚拟列中计算百分比。

this是查询: -

i want to calculate percentage and show it in datagridview(unbound) percentage column
but i want to calculate percentage from virtual columns selected from tables in query.
this is the query:-

select distinct  s.S_ID,s.Name ,(select  count(Pre) from Attendance where  a.C_ID=C_ID and a.S_ID=S_ID ) as Total_Classes,(select count(Pre) from Attendance where a.C_ID = C_ID and a.S_ID = S_ID and Pre = 'True') as Attended from Course c left outer join StudentCourse sc on c.C_ID = sc.C_ID left outer join Student s on s.S_ID = sc.S_ID left outer  join Attendance a on a.S_ID = s.S_ID and a.C_ID = c.C_ID where c.C_ID ='" + id + "'"



i我得到的百分比,但问题是每当我点击任何其他列然后百分比或现在(这些都是未绑定的列)百分比列不显示任何值。

,当加载datagridview时,它显示空白行,只有在按下百分比或者pres后才会填充它ent列,在检查当前列中的复选框后,它会显示该记录



我尝试过:




i am getting percentage but the problem is that whenever i click on any column other then Percentage or Present(both these are unbound columns) percentage columns doesnt show any value.
and when datagridview is loaded it shows blank rows it only gets populated after i press percentage or present column and after checking the checkbox in present column it then shows that record

What I have tried:

foreach (DataGridViewRow row in dataGridView1.Rows)
                       {
                double b = double.Parse(dataGridView1.Rows[row.Index].Cells[5].Value.ToString());
                //MessageBox.Show("b="+b);
                double c = double.Parse(dataGridView1.Rows[row.Index].Cells[4].Value.ToString());
                //MessageBox.Show("c="+c);
                int a =Convert.ToInt32(b/c*100);
                dataGridView1.Rows[row.Index].Cells[0].Value = a;

推荐答案

DataGridView.InvalidateCell Method(System.Windows.Forms)| Microsoft Docs [ ^ ]


这篇关于如何根据虚拟列值将公式放在datagridview列上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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