title: How to add empty value from gridview cell to list?
body: <p>I want to enter guest details(Title,Firstname,midname lastname) in a <code>list&lt;string&gt;</code> ,the guest details can be empty.I'm using LINQ for inserting in the list.I had referred this question for the LINQ code <a href="https://stackoverflow.com/questions/21314109/datagridview-write-all-values-from-a-column-to-list">DataGridView write all values from a column to list</a></p>
  
  <p>All I want to do is enter the text into the list if it has or insert empty string if it doesn't have.Right now if I leave textboxes blank it will throw <code>object reference not set to instance of an object exception</code></p>
  
  <pre><code>private string SaveGuestDetails()
          {
              string strRet = string.Empty;
              Reservation obj = new Reservation();
              FinalReservationDetails f = new FinalReservationDetails();
  
              try
              {
                  //int i = dgvTextBoxes.Rows.Count;
                  List&lt;DataRow&gt; personsList = new List&lt;DataRow&gt;();
                  int j = 0;
                  for (int i = 0; i &lt; dgvTextBoxes.Rows.Count; i++)
                  {
                      f.SubSrNo = j + 1;
  
                        f.GuestTitle = dgvTextBoxes.Rows
                     .OfType&lt;DataGridViewRow&gt;()
                     .Select(r =&gt; r.Cells["txtTitle"].Value.ToString())
                     .ToList();
  
                  f.FirstName = dgvTextBoxes.Rows
                      .OfType&lt;DataGridViewRow&gt;()
                      .Select(r =&gt; r.Cells["txtFname"].Value.ToString())
                      .ToList();
  
                  f.MidName = dgvTextBoxes.Rows
                      .OfType&lt;DataGridViewRow&gt;()
                      .Select(r =&gt; r.Cells["txtMName"].Value.ToString())
                      .ToList();
  
                  f.LastName = dgvTextBoxes.Rows
                      .OfType&lt;DataGridViewRow&gt;()
                      .Select(r =&gt; r.Cells["txtLname"].Value.ToString())
                      .ToList();
  
                   }
  
  
              }
              catch (Exception ex)
              {
  
              }
              return strRet;
          }
  </code></pre>