public void GetClientIdAndContractId() { var distinctClientId = ClientList.GroupBy(x => x.ClientId).Select(y => y.First()); List <int> clientIdList = new List <int>(); foreach (var clientId in distinctClientId) { clientIdList.Add(clientId.ClientId); } DistinctClientIdList = clientIdList; int selectedClientId = clientIdList[_clientIndex]; List <int> contractIdList = new List <int>(); foreach (var contractId in ClientList.Where(x => x.ClientId == selectedClientId)) { contractIdList.Add(contractId.ContractId); } SelectedClientId = selectedClientId; ContractIdList = contractIdList; SelectedContractId = ContractIdList[ContractIndex]; }