lundi 8 février 2021

C# - Loop through DataGridView Rows using foreach and if statement - Missing last entry

I have a DataGridView with a checkbox column.

enter image description here

Now I want to loop through all rows, with an active checkbox and print out the IdUser and True.

foreach (DataGridViewRow row in userDataGridView.Rows)
            {
                if (row.Cells[5].Value.ToString() == "True")
                {
                    MessageBox.Show(row.Cells[0].Value.ToString() + " - " + row.Cells[5].Value.ToString());
                }

            }


In this example the row with the IdUser 17 is the last selected one.

I don't know why, but I just see entry 15 as the last one. 17 is not shown any more...

Can anybody help?

Regards Lars

Aucun commentaire:

Enregistrer un commentaire