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:
Index was out of range. Must be non-negative and less than the size of the collection.
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?
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.
private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
string filename = dataGridView1[e.ColumnIndex, e.RowIndex].Value.ToString();
if (e.ColumnIndex == 3 && File.Exists(filename))
{
Process.Start(filename);
}
}
