title: System.DBNull Error on formatting DataGridView C#
body: <p>I'm new to C# so I have been following some guides and adapting it to fit my application. <a href="https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcellformattingeventargs(v=vs.110).aspx" rel="nofollow noreferrer">Here</a> is one of the ones I followed from Microsoft.</p>
  
  <p>I have used the same code as what they have suggested and I get an error. </p>
  
  <p><img src="https://i.stack.imgur.com/GDWwK.jpg" alt="enter image description here"></p>
  
  <p>My code simply looks at the data in the DataGridView and highlights the line with red if the condition is met.
  This is my code:</p>
  
  <pre><code>        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
      {
  
          //Set the row definition
          DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
          //If we are on the validating column
          if (this.dataGridView1.Columns[e.ColumnIndex].Name == "SelectedUID")
          {
              //check criteria
              string stringValue = (string)e.Value;
              if ((stringValue.IndexOf("JL") &gt; -1))
              {
                  Debug.WriteLine("The Format Value " + e.Value);
                  //format the row colour
                  row.DefaultCellStyle.ForeColor = Color.White;
                  row.DefaultCellStyle.BackColor = Color.Red;
              }
              else
              {
                  Debug.WriteLine("The Value " + e.Value);
              }
          }
  
      }
  </code></pre>
  
  <p>What is it that I have got wrong with the conversion of the object? I have tried many other solutions. Additional to this I tried to test:</p>
  
  <pre><code>if (e.value != null) 
  </code></pre>
  
  <p>but this did not even read a null value in there so I'm not sure what was being returned because I checked the length and it was 0.</p>