Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

C#
datagridview having 4 columns

c1 c2 c3 c4
c1 for int only
c2 for Alphabets only
c3 for x(multiplication)
c4 double xx(multiplication)

for eg:
c1 c2 c3 c4
5  A
2  B  2
4  C
4  D     3
2  A
2  B
2  C
2  D

using textbox1 for total (total should be come without any button click)
total = 74

explain of total
5A
2B X 2
(5 + 2)*2 = 14
5A
2B X 2
4C
4D    X 3
(((5 + 2)*2 = 14 + 4 + 4 )*3 = 66
66 + 2 + 2 + 2+ 2 = 74

also i want total of each alphabets like using four more labels

label1 A = 32
label2 B = 14
label3 C = 14
label4 D = 14
total = 74

please help me the code of datagridview sum of cell values using multiple multiplications so i can continued to my code for more implimentation.
Posted
Updated 29-Sep-14 20:04pm
v2
Comments
Sergey Alexandrovich Kryukov 30-Sep-14 2:13am    
What have you tried so far?
—SA
Sinisa Hajnal 30-Sep-14 2:14am    
There is no formula for this cumulative effect of multiplication. You'll have to loop through each row and keep score.
Member 10570811 30-Sep-14 2:18am    
Dear Sergey

i have tried to caluculate sum cell with using single multiplication also with double if nessesary.

help me the code

Please see:
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcell.value%28v=vs.110%29.aspx[^],
System.Windows.Forms.DataGridViewTextBoxCell[^],
http://msdn.microsoft.com/en-us/library/ch45axte.aspx[^].

Note: DataGridViewCell.Value should be type-cast to string for the cells supposed to be of the type System.Windows.Forms.DataGridViewTextBoxCell, and string.TryParse can be used to parse the strings to integers. Alternatively, you can create your own cell type derived from the abstract class DataGridViewCell. Sum up those integer values in appropriate loop.

—SA
 
Share this answer
 
v2
Use Linq[^], which enables you to "fetch" data from datagrid.

More:
101 LINQ Samples[^]
Aggregate Functions in Linq To SQL[^]
CodeProject Knowledge Base[^]

The alternative way is to Group, Sort, and Filter Data in the DataGrid Control[^] via CollectionView Class.
 
Share this answer
 
Comments
Member 10570811 30-Sep-14 3:08am    
Please Add Code here what i post

thanks
Maciej Los 30-Sep-14 5:11am    
Follow the links. There you'll find some piece of code.
Member 10570811 30-Sep-14 8:49am    
i could not get any idea using multiplication
i can only sum of rows
//cell value changed event handler
int sum = 0;
for (i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null)
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value.ToString());
label1.Text = Convert.ToString(sum);
}
}
help me code what i need
Member 10570811 6-Oct-14 2:37am    
please anybody help me the code

thanks
Member 10570811 13-Oct-14 2:00am    
hello,

could anybody solve this problem.

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