title: Getting "Index was out of range" exception in DataGridView when clicking header
body: <p>I am using a DataGridView to display my data from a SQLite database. One column is a directory to open pdfs assigned to the row. The code works but, every time I click on the column title, it gives me the error:</p>
  
  <blockquote>
    <p>Index was out of range. Must be non-negative and less than the size of the collection.</p>
  </blockquote>
  
  <p>Actually, any time I click the column text (just "PDF", or any other column's text) it throws that error. But when I click outside the text (anywhere in the ordering box), it reorders my columns, which is ok. Any ideas?</p>
  
  <p>The code works, opens up the PDF, but I don't want the user accidentally clicking the title text and the program crash. Here is the code for the datagridview to open the pdf.</p>
  
  <pre><code>  private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
      {
          string filename = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
          if (e.ColumnIndex == 3 &amp;&amp; File.Exists(filename))
          {
              Process.Start(filename);
          } 
     }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/X9nHy.png" alt="enter image description here"></p>