Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
created a datagridview and
Added number of rows
from 1 to 7
summation to results
1
2
3
4
5
6
7
=> results
1
3
6
10
15
21
28
(1+2=3; 3+3=6; 6+4=10; 10+5=15; 15+6=21; 21+7=28)
write simple way
VB
DataGridView1.RowCount = 9
        For i As Integer = 1 To 7
            DataGridView1.Rows(i).Cells(0).Value = i
        Next
        Dim kq1 As Integer = 0
        Dim kq2 As Integer = 0
        Dim kq3 As Integer = 0
        Dim kq4 As Integer = 0
        Dim kq5 As Integer = 0
        Dim kq6 As Integer = 0
        Dim kq7 As Integer = 0
        Dim a As Integer = DataGridView1.Rows(0).Cells(0).Value
        Dim b As Integer = DataGridView1.Rows(1).Cells(0).Value
        Dim c As Integer = DataGridView1.Rows(2).Cells(0).Value
        Dim d As Integer = DataGridView1.Rows(3).Cells(0).Value
        Dim e1 As Integer = DataGridView1.Rows(4).Cells(0).Value
        Dim f As Integer = DataGridView1.Rows(5).Cells(0).Value
        Dim g As Integer = DataGridView1.Rows(6).Cells(0).Value
        kq1 = a + b
        kq2 = c + kq1
        kq3 = d + kq2
        kq4 = e1 + kq3
        kq5 = f + kq4
        kq6 = g + kq5
        DataGridView1.Rows(0).Cells(0).Value = kq1
        DataGridView1.Rows(1).Cells(0).Value = kq2
        DataGridView1.Rows(2).Cells(0).Value = kq3
        DataGridView1.Rows(3).Cells(0).Value = kq4
        DataGridView1.Rows(4).Cells(0).Value = kq5
        DataGridView1.Rows(5).Cells(0).Value = kq6

if adding new rows can't controlled
please help with all of the more compact form
Posted
Comments
syed shanu 25-Jan-15 21:19pm    
Hi,
Are you looking result like this.
C# Code
dataGridView1.RowCount = 9;
int IncValue=0;

for (int iVal = 1; iVal <= 7; iVal++)
{
IncValue = IncValue + iVal;
dataGridView1.Rows[iVal].Cells[0].Value = IncValue;

}

VB.NET CODE

DataGridView1.RowCount = 9
Dim IncValue As Integer = 0

For i As Integer = 1 To 7
IncValue=IncValue+i;
DataGridView1.Rows(i).Cells(0).Value = IncValue
Next

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