private bool GetTimesheetListViewItem(Timesheet timesheet, out ListViewItem timesheetListViewItem, bool createIfNotExists) { int itemCount = m_timesheetsListView.Items.Count; if (itemCount == 0) { timesheetListViewItem = createIfNotExists ? CreateTimesheetListViewItem(timesheet) : null; return(false); } else { foreach (ListViewItem listViewItem in m_timesheetsListView.Items) { if (listViewItem.Tag is Timesheet) { Timesheet timeheetToCheck = (Timesheet)listViewItem.Tag; if (timeheetToCheck.Equals(timesheet)) { timesheetListViewItem = listViewItem; return(true); } } } // If we get here there is no ListViewItem associated with the timesheet in the ListView... timesheetListViewItem = createIfNotExists ? CreateTimesheetListViewItem(timesheet) : null; return(false); } }