By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,378 Members | 3,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,378 IT Pros & Developers. It's quick & easy.

how to Add column cell value to previos cell value and get result

P: 1
this my code
iwant to add column cellvalue in datagridview to previouse number of cells user insert
the summ variable always equal zero


any help
Expand|Select|Wrap|Line Numbers
  1.  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         year = TextBox1.Text
  3.         month = TextBox2.Text
  4.         noofmonths = TextBox3.Text
  5.         Dim summ As String
  6.         summ = 0
  7.         Dim rowindex As Integer
  8.  
  9.  
  10.  
  11.         For Each row As DataGridViewRow In DataGridView1.Rows
  12.             If row.Cells.Item(1).Value = TextBox1.Text Then
  13.                 If row.Cells.Item(2).Value = TextBox2.Text Then
  14.                     rowindex = row.Index
  15.  
  16.  
  17.  
  18.  
  19.                     For i As Integer = rowindex To noofmonths And i <> 0
  20.  
  21.                         summ = row.Cells.Item(3).Value + summ
  22.  
  23.  
  24.                         rowindex = row.Index - 1
  25.  
  26.                         i = i - 1
  27.  
  28.  
  29.  
  30.  
  31.                     Next
  32.                     summ = summ / noofmonths.ToString
  33.  
  34.                     rowindex = rowindex + noofmonths
  35.                     Dim actie As String = row.Cells(3).Value.ToString()
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.                     row.Cells(4).Value = summ
  50.  
  51.                     MsgBox(summ)
  52.  
  53.                 Else
  54.  
  55.                     MsgBox("Item not found")
  56.  
  57.                 End If
  58.             End If
  59.  
  60.  
  61.         Next
May 2 '15 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.