title: Error message "Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
body: <p>I have a <code>DataGridView</code>. I want to add column 4 values. I wrote this code. But it shows above error on <code>Total += Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[4].Value);</code>.</p>
  
  <pre><code> decimal Total = 0;
  
   for (int i = 0; i &lt; dgvSalesFooterAdd.Rows.Count; i++)
   {
        dgvSalesFooterAdd.Rows[i].Cells[4].Value = 
            Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[3].Value) * 
            Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[3].Value);
  
            Total += Convert.ToDecimal(dgvSalesFooterAdd.Rows[i].Cells[4].Value);
   }
   lblFinalTotalAdd.Text = Total.ToString();
  </code></pre>
  
  <p><em><strong>Creating 5th column code:</em></strong></p>
  
  <pre><code>            OleDbConnection con = new OleDbConnection(conn);
              con.Open();
              DataTable dtusers = new DataTable();
              OleDbCommand cmd = new OleDbCommand("Select Shorts,Code,Description,Percentage from SalesFields", con);
              OleDbDataAdapter da = new OleDbDataAdapter(cmd);
              da.Fill(dtusers);
              dgvSalesFooterAdd.DataSource = dtusers;
              dgvSalesFooterAdd.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
              dgvSalesFooterAdd.Columns[0].Name = "Shorts";
              dgvSalesFooterAdd.Columns[1].Name = "Code";
              dgvSalesFooterAdd.Columns[2].Name = "Description";
              dgvSalesFooterAdd.Columns[3].Name = "Percentage";
              dgvSalesFooterAdd.Columns[0].HeaderText = "Shorts";
              dgvSalesFooterAdd.Columns[1].HeaderText = "Code";
              dgvSalesFooterAdd.Columns[2].HeaderText = "Description";
              dgvSalesFooterAdd.Columns[3].HeaderText = "Percentage";
              DataGridViewColumn amount = new DataGridViewColumn();
              amount.HeaderText = "Amount";
              amount.Name = "Amount";
              amount.CellTemplate = new DataGridViewTextBoxCell();
              dgvSalesFooterAdd.Columns.Insert(4, amount);
              con.Close();
  
              con.Close();
  </code></pre>