This code works anywhere else.. form load, button click, etc. But when I add it to my tripsBindingSource_PositionChanged it says object reference not set to an instance of an object when its getting the selected row index. I’m assuming there is no selected row yet but why would it work at form load than? It is making my app bomb at run time. What can I do to fix this? Thanks!
private void tripsBindingSource_PositionChanged(object sender, EventArgs e)
{
//get selected row index
int index = this.dgvTripGrid.CurrentRow.Index;
//get pk of selected row using index
string cellValue = dgvTripGrid["pkTrips", index].Value.ToString();
//change pk string to int
int pKey = Int32.Parse(cellValue);
...
}
You have to check if the row is null first and then only do your load if it is not null