title: How do I automate a date to be inserted into a datagridview?
body: <p><strong>[This is solved, i have added the answer at the bottom]</strong></p>
  
  <p><strong>[Original Question]</strong>
  How do I automate adding a date to be inserted into a datagridview?</p>
  
  <p>The datagridview is not binded or sourced to any SQL server as anything that user will write into the DataGridView will then be extracted and converted into a pdf table. However the dates inside the DataGridView is to be fixed with a value of today's date.</p>
  
  <p><a href="https://i.stack.imgur.com/NdAPC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NdAPC.png" alt="DataGridView Picture"></a></p>
  
  <p>My end result should be as per picture below :</p>
  
  <p><a href="https://i.stack.imgur.com/BTNMb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BTNMb.png" alt="enter image description here"></a></p>
  
  <p>I tried using code below to automate adding dates into new rows but it didnt work.</p>
  
  <pre><code>dt.Rows.Add("CurrentDate",System.Type.GetType("System.DateTime"));
  </code></pre>
  
  <p>Note - i did add a datatable.</p>
  
  <p>I also changed the method from CellContentClick to CellContentDoubleClick.</p>
  
  <p><strong>Edit 1 :</strong></p>
  
  <p>I updated the DGV as apparently i still require a  datatable to assign as a source to make this work.</p>
  
  <p>Here's my code :</p>
  
  <pre><code>pretable = new DataTable();
              pretable.Columns.Add("NO", typeof(int));
              pretable.Columns.Add("ID", typeof(string));
              pretable.Columns.Add("LO", typeof(string));
              pretable.Columns.Add("QT", typeof(string));
              pretable.Columns.Add("DA", typeof(DateTime));
              pretable.Columns["DA"].DefaultValue = DateTime.Now;
              pretable.Columns.Add("ER", typeof(string));
              pretable.Columns.Add("RE", typeof(string));
              DataRow row = pretable.NewRow();
              row["DA"] = DateTime.Now;
              pretable.Rows.Add(row);
              dataGridView1.DataSource = pretable;
              dataGridView1.Rows[5].Cells["DACL"].Value = DateTime.Now;
  </code></pre>
  
  <p>DA = Date Column in DataTable</p>
  
  <p>DACL = the name of the Date Column in DGV</p>
  
  <p>However , my results added only an empty row as per picture below.
  <a href="https://i.stack.imgur.com/XNM0K.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XNM0K.png" alt="enter image description here"></a></p>
  
  <p>.</p>
  
  <p>.</p>
  
  <p><strong>[ANSWER]</strong></p>
  
  <p>Previously on Form_Load, i added a DataTable, however i found out that this DataTable does not need to be bounded to the DGV as a Source for the date to work.</p>
  
  <p>so instead on Form_Load i added this code </p>
  
  <pre><code>dataGridView1.Rows[0].Cells["DACL"].Value = DateTime.Now.ToString("dd/MM/yyyy");
  dataGridView1.Rows[0].Cells["NOCL"].Value = totalRowsN;
  </code></pre>
  
  <p>This will work as my first Row Numbering and Date insertion.</p>
  
  <p><strong>Thanks to ZedLepplin below for providing the base answer.</strong></p>
  
  <p>I found out that DataGridView1_CellContentDoubleClick takes way too much click for the event to happen so instead i did DataGridView1_CellClick where insertion now takes less effort.</p>
  
  <p>The code i used is :</p>
  
  <pre><code>private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
          {
              totalRowsC = dataGridView1.Rows.Count-1;
              totalRowsN = dataGridView1.Rows.Count;
              dataGridView1.Rows[totalRowsC].Cells["DACL"].Value = DateTime.Now.ToString("dd/MM/yyyy");
              dataGridView1.Rows[totalRowsC].Cells["NOCL"].Value = totalRowsN;
          }
  </code></pre>
  
  <p>What this does is that TotalRowsC will be the value of Index for the code </p>
  
  <pre><code>dataGridView.Rows[Index].Cells[ColumnName]
  </code></pre>
  
  <p>So that it fits programming index. Programming indexes starts with 0 even though the row we see is 1. If i do not minus one in TotalRowsC , an error will prompt stating that we need to insert a value that fits the existing index.</p>
  
  <p>Problem solved for Date automation.
  Thank you everyone for the assistance.</p>