Click here to Skip to main content
14,329,910 members
Rate this:
Please Sign up or sign in to vote.
See more:
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 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());
                double c = double.Parse(dataGridView1.Rows[row.Index].Cells[4].Value.ToString());
                int a =Convert.ToInt32(b/c*100);
                dataGridView1.Rows[row.Index].Cells[0].Value = a;
Updated 14-May-19 16:10pm

1 solution

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100