Every time I click any cell this is the error that pops up. Here is a copy of my code. What's wrong with it? Any suggestions?
private void CarsdataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
{
this.CarsdataGridView.DefaultCellStyle.SelectionBackColor = selectionBackColor;
this.CarsdataGridView.DefaultCellStyle.SelectionForeColor = selectionForeColor;
var selectedCarData = CarsdataGridView.SelectedRows[0].DataBoundItem as CarsData;
if (selectedCarData != null)
{
txtId.Text = CarsdataGridView.SelectedRows[0].Cells[0].Value.ToString();
txtModel.Text = CarsdataGridView.SelectedRows[0].Cells[1].Value.ToString();
txtYear.Text = CarsdataGridView.SelectedRows[0].Cells[2].Value.ToString();
txtGearBox.Text = CarsdataGridView.SelectedRows[0].Cells[3].Value.ToString();
txtColor.Text = CarsdataGridView.SelectedRows[0].Cells[4].Value.ToString();
txtMax_Speed.Text = CarsdataGridView.SelectedRows[0].Cells[5].Value.ToString();
}
}