static void RegenerateRows( UpdateReportListView listView, List <ErrorMessage> errorMessages, TreeViewItem rootItem, List <TreeViewItem> rows) { ClearRows(rootItem, rows); if (errorMessages.Count == 0) { return; } for (int i = 0; i < errorMessages.Count; i++) { ErrorListViewItem errorListViewItem = new ErrorListViewItem(i + 1, errorMessages[i]); rootItem.AddChild(errorListViewItem); rows.Add(errorListViewItem); } listView.SetSelection(new List <int> { 1 }); }