I have an app that populates several data tables on load. Each of
these are bound to a datagrid. Above each datagrid I have several
text boxes that display the data for the active row. There are
buttons to allow the user to add, update, and delete a row in the
grid. I have an event on cell changed associated with the grid that
updates the text boxes so they are always current.
When the delete button is used I'm getting an error that ""Deleted row
information cannot be accessed through the row."
Here's what I want to happen:
1. User selects a row
2. The contents of the row appear in the appropiate text boxes
3. User presses delete button
4. Row is marked for deletion when dataset changes are written back
and not shown in the grid
5. text boxes are updated to show the next row.
Here's my method to update the text boxes:
UpdateTextBoxes()
{
int curSelection = dgMembForm.CurrentRowIndex;
DataRow r = dTable.Rows[curSelection];
txtMemberName.Text = r["Account"].ToString();
rtbMemberFormula.Text = r["Member Formula"].ToString();
)
The event on cell changed just calls this method
Heres the code for the delete button:
private void btnDelete_Click(object sender, EventArgs e)
{
DataRow selectedRow = this.SelectedRow(dTable,
dgMembForm);
int sRow = dgMembForm.CurrentCell.RowNumber;
dTable.Rows[sRow].Delete();
dgMembForm.CurrentRowIndex = 0;
UpdateTextBoxes();
}
I added the piece to set index to 0 to solve a similar problem when
the last row was deleted.