} // end method BtnSearch_Click() /// <summary> /// To find the search terms in the list /// </summary> private void Search() { //Declare & Init vars: ListViewItem item1 = null; ListViewItem item2 = null; //If an ID is given if (!String.IsNullOrWhiteSpace(TxtID.Text)) { //Validate given empID if (Validator.EmpID(TxtID.Text)) { item1 = ListAllEmp.FindItemWithText(TxtID.Text, true, 0); try { ListAllEmp.Items[item1.Index].Focused = true; ListAllEmp.Items[item1.Index].Selected = true; ListAllEmp.Select(); } // end try catch (NullReferenceException) { //Prompt user, search values not found MessageBox.Show(INVALID_SEARCH_MSG, INVALID_SEARCH_CAPTION); } // end catch } // end if else // empID is invalid { //Show MessageBox prompting user of invalid field MessageBox.Show(INVALID_ID_MSG, INVALID_ID_CAPTION); } // end else } // end if //If a last name is given if (!String.IsNullOrWhiteSpace(TxtLName.Text)) { //Validate given last name if (Validator.Name(TxtLName.Text)) { item2 = ListAllEmp.FindItemWithText(TxtLName.Text, true, 0); try { ListAllEmp.Items[item2.Index].Focused = true; ListAllEmp.Items[item2.Index].Selected = true; ListAllEmp.Select(); } // end try catch (NullReferenceException) { //Prompt user, search values not found MessageBox.Show(INVALID_SEARCH_MSG, INVALID_SEARCH_CAPTION); } // end catch } // end if else // last name is invalid { //Show MessageBox prompting user of invalid field MessageBox.Show(INVALID_LNAME_MSG, INVALID_LNAME_CAPTION); } // end else } // end if } // end method Search()
} // end method PopulateEmployeeList() /// <summary> /// To sort the column subitems in alphanumeric-ascending /// </summary> /// <param name="sender">The object generating the event</param> /// <param name="e">The column click event args</param> private void ListAllEmp_ColumnClick(object sender, ColumnClickEventArgs e) { // Set the ListViewItemSorter property to a new ListViewItemComparer ListAllEmp.ListViewItemSorter = new ListViewSort(e.Column); // Call the sort method to manually sort. ListAllEmp.Sort(); } // end method ListAllEmp_ColumnClick()