samedi 28 février 2015

DataGridView "index -1 does not have a value" in release build

I have a problem with DataGridView in WindowsForms Application created in VS 2013. Application works with no exceptions in Debug build, but when I switch to Release build, and try to click on datagridview cell I have an exception:



Exception:Thrown: "Index -1 does not have a value." (System.IndexOutOfRangeException) A System.IndexOutOfRangeException was thrown: "Index -1 does not have a value." Time: 2015-02-28 19:19:29 Thread:[13944]



Here is the code which do the stuff:



private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dgvList.Refresh();
var senderGrid = (DataGridView)sender;

if (e.RowIndex >= 0)
{
if (senderGrid.Columns[e.ColumnIndex].Name == "Delete")
{
Book b = (Book)dgvList.CurrentCell.OwningRow.DataBoundItem;
ArrayOfBooks.Remove(b);
fillGV();
}
}
}

private void dgvList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
dgvList.Refresh();
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex].Name == "Author" && e.RowIndex >= 0)
{
Book b = (Book)dgvList.CurrentCell.OwningRow.DataBoundItem;
frmAuthors frmAuth = new frmAuthors(b);
frmAuth.mainForm = this;
frmAuth.Show();
}
}


What is more in that app I have second form with very similar code and it works well. I found answer for similar question(here) but it doesn't help me.


Aucun commentaire:

Enregistrer un commentaire