public void DeleteAddressCommand() { try { int i = 0; int ii = 0; for (int j = SelectedAddressList.Count - 1; j >= 0; j--) { Address item = (Address)SelectedAddressList[j]; //get Max Index... i = AddressList.IndexOf(item); if (i > ii) { ii = i; } Delete(item); AddressList.Remove(item); } if (AddressList != null && AddressList.Count > 0) { //back off one index from the max index... ii = ii - 1; //if they delete the first row... if (ii < 0) { ii = 0; } //make sure it does not exceed the list count... if (ii >= AddressList.Count()) { ii = AddressList.Count - 1; } SelectedAddress = AddressList[ii]; //we will only enable committ for dirty validated records... if (Dirty == true) { AllowCommit = CommitIsAllowed(); } else { AllowCommit = false; } } else//only one record, deleting will result in no records... { SetAsEmptySelection(); } }//we try catch company delete as it may be used in another table as a key... //As well we will force a refresh to sqare up the UI after the botched delete... catch { NotifyMessage("Address/s Can Not Be Deleted. Contact XERP Admin For More Details."); Refresh(); } }