private void dataGridViewDistances_CellClick(object sender, DataGridViewCellEventArgs e) { string text = null; try { if (e.RowIndex == -1) { return; } if (e.ColumnIndex == 0 && e.RowIndex < dataGridViewDistances.Rows.Count) { Object ob = dataGridViewDistances[e.ColumnIndex, e.RowIndex].Value; if (ob != null) { text = ob.ToString(); } System.Diagnostics.Trace.WriteLine("Click:" + e.RowIndex.ToString() + ":" + e.ColumnIndex.ToString()); if (!string.IsNullOrEmpty(text)) { try { System.Windows.Forms.Clipboard.SetText(text); } catch { _discoveryForm.LogLineHighlight("Copying text to clipboard failed"); } } } } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("Exception dataGridViewDistances_CellClick: " + ex.Message); System.Diagnostics.Trace.WriteLine("Trace: " + ex.StackTrace); } }