So in my code, I have a delete button then when clicked will remove the selected rows from the Grid.
This appears to work at the UI level.
But when I had to rederive my data from the cells in the Grid, somehow the stuff I just deleted was still in there. I learned this as I was looping through line by line in debug mode.
My Base algorithm came from this stackoverflow post's first answer. Now I looked at the MSDN here about what RemoveAt actually does Unfortunately, it wasn't very enlightening.
Removes the row at the specified position from the collection.
Here is my code.
private void Delete_Click(object sender, EventArgs e)
{
if (this.DataView.SelectedRows.Count > 0)
{
foreach (DataGridViewRow item in DataView.SelectedRows)
{
DataView.Rows.RemoveAt(item.Index);
}
}
refreshDataFromGrid();
}
Now here is the part that derives the Data from what is in the Grid
private void refreshDataFromGrid()
{
//if the rows in the gridview aren't empty copy them over to the String array in d.value
for (int i = 0; i < DataView.Rows.Count; i++)
{
for (int j = 0; j < DataView.Rows[i].Cells.Count; j++)
{
if (DataView.Rows[i].Cells[j].ToString() != "")
{
(DataViewParent as STS_Console.MenuItems.MenuItem).d.Value[i, j] = DataView.Rows[i].Cells[j].Value.ToString();
}
}
}
}
I would be glad to provide screenshots or anything else as necessary, just ask.