none
DataGridView_RowLeave misbehaving at DGV Load time RRS feed

  • Question

  • When I load my dataGridView, it is triggering my dgv_RowLeave procedure and throwing an error because there is not really a selected row to process on.  But I can't find a way to wrap the statement in an If statement when the grid is loading.  Once the grid is loaded, it works just fine.   The dgvSQL != null is not doing anything here.  It was just a test.  

    For testing purposes, I am using this code: 

    private void dgvSQL_RowLeave(object sender, DataGridViewCellEventArgs e) { if (dgvSQL != null) { MessageBox.Show("Going to check for updates on PK: " + dgvSQL.SelectedRows[0].Cells["SanctionsListPK"].Value.ToString() + Environment.NewLine +
    "For rowIndex: " + e.RowIndex.ToString());

    } }


    Thursday, January 31, 2019 5:18 PM

Answers

All replies

  • Just check the RowIndex

    if (e.RowIndex > -1)  

    • Marked as answer by cboshdave Thursday, January 31, 2019 7:40 PM
    Thursday, January 31, 2019 5:24 PM
  • For some reason the e.RowIndex = 0 in this instance.  Not sure why.  This triggered the idea that I could simiarly check for dgvSQL.SelectedRows.Count > 0 and that worked. Thanks!
    Thursday, January 31, 2019 7:40 PM