hi,
I have One GridView. In My Gridview there are two Combobox columns like Country and State.
When I Change Country that time State will have to change.
In My simple application it work but in MVVM it does not work.
Please Help me.
My VIEW-MODEL Class Looks Like this:
using System;
using System.Net;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
//using SilverlightWithWCFService.ServiceReference1;
using Telerik.Windows.Controls;
using System.ComponentModel;
using System.Collections.Generic;
namespace SilverlightWithWCFService.Model
{
public class CustomerViewModel : INotifyPropertyChanged
{
private int cID;
public int CID
{
get
{
return this.cID;
}
set
{
this.cID = value;
this.OnPropertyChanged("CID");
CustromerList c = new CustromerList() { Country = CID };
StateList = c.AvailableState.ToList();
}
}
private ObservableCollection<CustromerList> objsearchList;
public ObservableCollection<CustromerList> objSearchList
{
get
{
return this.objsearchList;
}
set
{
this.objsearchList = value;
this.OnPropertyChanged("objSearchList");
}
}
List<Country> countryList = new List<Country>();
public List<Country> CountryList
{
get { return countryList; }
set
{
this.countryList = value;
this.OnPropertyChanged("CountryList");
}
}
List<State> stateList = new List<State>();
public List<State> StateList
{
get
{
CustromerList c = new CustromerList() { Country = CID };
stateList = c.AvailableState.ToList();
return stateList;
}
set
{
this.stateList = value;
this.OnPropertyChanged("StateList");
}
}
public CustomerViewModel()
{
countryList = AllLocations.Countries;
CountryList = countryList;
CID = 1;
objsearchList = new ObservableCollection<CustromerList>();
for (int i = 1; i <= 10; i++)
{
objsearchList.Add(new CustromerList()
{
CustomerID = i,
CompanyName = i.ToString(),
ContactName = i.ToString(),
Country = 1,
State = 1
});
objSearchList = objsearchList;
//SampleServiceClient client = new SampleServiceClient();
//client.CustomerListCompleted += new EventHandler<CustomerListCompletedEventArgs>(client_CustomerListCompleted);
//client.CustomerListAsync();
}
}
//void client_CustomerListCompleted(object sender, CustomerListCompletedEventArgs e)
//{
// objsearchList = new ObservableCollection<CustromerList>();
// foreach (Customer item in e.Result)
// {
// objsearchList.Add(new CustromerList()
// {
// CustomerID = item.CustomerName,
// CompanyName = item.CompanyName,
// ContactName = item.ContactName,
// Country = 1,
// State = 1
// });
// }
// objSearchList = objsearchList;
//}
void OnPropertyChanged(string property)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(property));
}
public event PropertyChangedEventHandler PropertyChanged;
}
#region Classes
public class Country
{
public int CountryID { get; set; }
public string CountryName { get; set; }
}
public class State
{
public int StateID { get; set; }
public string StateName { get; set; }
public int CountryID { get; set; }
}
public class CustromerList : INotifyPropertyChanged
{
private int customerID;
public int CustomerID
{
get
{
return this.customerID;
}
set
{
if (this.customerID != value)
{
this.customerID = value;
this.OnPropertyChanged("CustomerID");
}
}
}
private string companyName;
public string CompanyName
{
get
{
return this.companyName;
}
set
{
if (this.companyName != value)
{
this.companyName = value;
this.OnPropertyChanged("CompanyName");
}
}
}
private string contactName;
public string ContactName
{
get
{
return this.contactName;
}
set
{
if (this.contactName != value)
{
this.contactName = value;
this.OnPropertyChanged("ContactName");
}
}
}
private int country;
public int Country
{
get
{
return this.country;
}
set
{
if (this.country != value)
{
this.country = value;
this.OnPropertyChanged("Country");
this.State = null;
}
}
}
private int? state;
public int? State
{
get
{
return this.state;
}
set
{
if (this.state != value)
{
this.state = value;
this.OnPropertyChanged("State");
}
}
}
public IEnumerable<State> AvailableState
{
get
{
return from c in AllLocations.States
where c.CountryID == this.Country
select c;
}
}
void OnPropertyChanged(string property)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(property));
}
public event PropertyChangedEventHandler PropertyChanged;
}
public static class AllLocations
{
public static List<Country> Countries;
public static List<State> States;
static AllLocations()
{
Countries = new List<Country>();
Countries.Add(new Country() { CountryID = 1, CountryName = "Asia" });
Countries.Add(new Country() { CountryID = 2, CountryName = "Europe" });
Countries.Add(new Country() { CountryID = 3, CountryName = "Africa" });
Countries.Add(new Country() { CountryID = 4, CountryName = "Oceania" });
Countries.Add(new Country() { CountryID = 5, CountryName = "North America" });
Countries.Add(new Country() { CountryID = 6, CountryName = "South America" });
Countries.Add(new Country() { CountryID = 7, CountryName = "Antarctica" });
States = new List<State>();
States.Add(new State() { StateID = 1, CountryID = 1, StateName = "Afghanistan, Islamic Republicof" });
States.Add(new State() { StateID = 3, CountryID = 2, StateName = "Albania, Republic of" });
States.Add(new State() { StateID = 4, CountryID = 3, StateName = "Algeria, Peoples DemocraticRepublic of" });
States.Add(new State() { StateID = 5, CountryID = 4, StateName = "American Samoa" });
States.Add(new State() { StateID = 6, CountryID = 2, StateName = "Andorra, Principality of" });
States.Add(new State() { StateID = 7, CountryID = 3, StateName = "Angola, Republic of" });
States.Add(new State() { StateID = 8, CountryID = 5, StateName = "Anguilla" });
States.Add(new State() { StateID = 9, CountryID = 7, StateName = "Antarctica (the territory South of 60 deg S)" });
States.Add(new State() { StateID = 10, CountryID = 5, StateName = "Antigua and Barbuda" });
States.Add(new State() { StateID = 11, CountryID = 6, StateName = "Argentina, Argentine Republic" });
States.Add(new State() { StateID = 12, CountryID = 1, StateName = "Armenia, Republic of" });
States.Add(new State() { StateID = 13, CountryID = 5, StateName = "Aruba" });
States.Add(new State() { StateID = 14, CountryID = 4, StateName = "Australia, Commonwealth of" });
States.Add(new State() { StateID = 15, CountryID = 2, StateName = "Austria, Republic of" });
States.Add(new State() { StateID = 16, CountryID = 1, StateName = "Azerbaijan, Republic of" });
States.Add(new State() { StateID = 17, CountryID = 5, StateName = "Bahamas, Commonwealth of the" });
States.Add(new State() { StateID = 18, CountryID = 1, StateName = "Bahrain, Kingdom of" });
States.Add(new State() { StateID = 19, CountryID = 1, StateName = "Bangladesh, Peoples Republic of" });
States.Add(new State() { StateID = 20, CountryID = 5, StateName = "Barbados" });
States.Add(new State() { StateID = 21, CountryID = 2, StateName = "Belarus, Republic of" });
States.Add(new State() { StateID = 22, CountryID = 2, StateName = "Belgium, Kingdom of" });
States.Add(new State() { StateID = 23, CountryID = 5, StateName = "Belize" });
States.Add(new State() { StateID = 24, CountryID = 3, StateName = "Benin, Republic of" });
States.Add(new State() { StateID = 25, CountryID = 5, StateName = "Bermuda" });
States.Add(new State() { StateID = 26, CountryID = 1, StateName = "Bhutan, Kingdom of" });
States.Add(new State() { StateID = 27, CountryID = 6, StateName = "Bolivia, Republic of" });
States.Add(new State() { StateID = 28, CountryID = 2, StateName = "Bosnia and Herzegovina" });
States.Add(new State() { StateID = 29, CountryID = 3, StateName = "Botswana, Republic of" });
States.Add(new State() { StateID = 30, CountryID = 7, StateName = "Bouvet Island (Bouvetoya)" });
States.Add(new State() { StateID = 31, CountryID = 6, StateName = "Brazil, Federative Republic of" });
States.Add(new State() { StateID = 32, CountryID = 1, StateName = "British Indian Ocean Territory (Chagos Archipelago)" });
States.Add(new State() { StateID = 33, CountryID = 5, StateName = "British Virgin Islands" });
States.Add(new State() { StateID = 34, CountryID = 1, StateName = "Brunei Darussalam" });
States.Add(new State() { StateID = 35, CountryID = 2, StateName = "Bulgaria, Republic of" });
States.Add(new State() { StateID = 36, CountryID = 3, StateName = "Burkina Faso" });
States.Add(new State() { StateID = 37, CountryID = 3, StateName = "Burundi, Republic of" });
States.Add(new State() { StateID = 38, CountryID = 1, StateName = "Cambodia, Kingdom of" });
States.Add(new State() { StateID = 39, CountryID = 3, StateName = "Cameroon, Republic of" });
States.Add(new State() { StateID = 40, CountryID = 5, StateName = "Canada" });
States.Add(new State() { StateID = 41, CountryID = 3, StateName = "Cape Verde, Republic of" });
States.Add(new State() { StateID = 42, CountryID = 5, StateName = "Cayman Islands" });
States.Add(new State() { StateID = 43, CountryID = 3, StateName = "Central African Republic" });
States.Add(new State() { StateID = 44, CountryID = 3, StateName = "Chad, Republic of" });
States.Add(new State() { StateID = 45, CountryID = 6, StateName = "Chile, Republic of" });
States.Add(new State() { StateID = 46, CountryID = 1, StateName = "China, Peoples Republic of" });
States.Add(new State() { StateID = 47, CountryID = 1, StateName = "Christmas Island" });
States.Add(new State() { StateID = 48, CountryID = 1, StateName = "Cocos (Keeling) Islands" });
States.Add(new State() { StateID = 49, CountryID = 6, StateName = "Colombia, Republic of" });
States.Add(new State() { StateID = 50, CountryID = 3, StateName = "Comoros, Union of the" });
States.Add(new State() { StateID = 51, CountryID = 3, StateName = "Congo, Democratic Republic ofthe" });
States.Add(new State() { StateID = 52, CountryID = 3, StateName = "Congo, Republic of the" });
States.Add(new State() { StateID = 53, CountryID = 4, StateName = "Cook Islands" });
States.Add(new State() { StateID = 54, CountryID = 5, StateName = "Costa Rica, Republic of" });
States.Add(new State() { StateID = 55, CountryID = 3, StateName = "Cote d'Ivoire, Republic of" });
States.Add(new State() { StateID = 56, CountryID = 2, StateName = "Croatia, Republic of" });
States.Add(new State() { StateID = 57, CountryID = 5, StateName = "Cuba, Republic of" });
States.Add(new State() { StateID = 58, CountryID = 1, StateName = "Cyprus, Republic of" });
States.Add(new State() { StateID = 59, CountryID = 2, StateName = "Czech Republic" });
States.Add(new State() { StateID = 60, CountryID = 2, StateName = "Denmark, Kingdom of" });
States.Add(new State() { StateID = 61, CountryID = 3, StateName = "Djibouti, Republic of" });
States.Add(new State() { StateID = 62, CountryID = 5, StateName = "Dominica, Commonwealth of" });
States.Add(new State() { StateID = 63, CountryID = 5, StateName = "Dominican Republic" });
States.Add(new State() { StateID = 64, CountryID = 6, StateName = "Ecuador, Republic of" });
States.Add(new State() { StateID = 65, CountryID = 3, StateName = "Egypt, Arab Republic of" });
States.Add(new State() { StateID = 66, CountryID = 5, StateName = "El Salvador, Republic of" });
States.Add(new State() { StateID = 67, CountryID = 3, StateName = "Equatorial Guinea, Republic of" });
States.Add(new State() { StateID = 68, CountryID = 3, StateName = "Eritrea, State of" });
States.Add(new State() { StateID = 69, CountryID = 2, StateName = "Estonia, Republic of" });
States.Add(new State() { StateID = 70, CountryID = 3, StateName = "Ethiopia, Federal DemocraticRepublic of" });
States.Add(new State() { StateID = 71, CountryID = 2, StateName = "Faroe Islands" });
States.Add(new State() { StateID = 72, CountryID = 6, StateName = "Falkland Islands (Malvinas)" });
States.Add(new State() { StateID = 73, CountryID = 4, StateName = "Fiji, Republic of the Fiji Islands" });
States.Add(new State() { StateID = 74, CountryID = 2, StateName = "Finland, Republic of" });
States.Add(new State() { StateID = 75, CountryID = 2, StateName = "France, French Republic" });
States.Add(new State() { StateID = 76, CountryID = 6, StateName = "French Guiana" });
States.Add(new State() { StateID = 77, CountryID = 4, StateName = "French Polynesia" });
States.Add(new State() { StateID = 78, CountryID = 7, StateName = "French Southern Territories" });
States.Add(new State() { StateID = 79, CountryID = 3, StateName = "Gabon, Gabonese Republic" });
States.Add(new State() { StateID = 80, CountryID = 3, StateName = "Gambia, Republic of the" });
States.Add(new State() { StateID = 81, CountryID = 1, StateName = "Georgia" });
States.Add(new State() { StateID = 82, CountryID = 2, StateName = "Germany, Federal Republic of" });
States.Add(new State() { StateID = 83, CountryID = 3, StateName = "Ghana, Republic of" });
States.Add(new State() { StateID = 84, CountryID = 2, StateName = "Gibraltar" });
States.Add(new State() { StateID = 85, CountryID = 2, StateName = "Greece, Hellenic Republic" });
States.Add(new State() { StateID = 86, CountryID = 5, StateName = "Greenland" });
States.Add(new State() { StateID = 87, CountryID = 5, StateName = "Grenada" });
States.Add(new State() { StateID = 88, CountryID = 5, StateName = "Guadeloupe" });
States.Add(new State() { StateID = 89, CountryID = 4, StateName = "Guam" });
States.Add(new State() { StateID = 90, CountryID = 5, StateName = "Guatemala, Republic of" });
States.Add(new State() { StateID = 91, CountryID = 2, StateName = "Guernsey, Bailiwick of" });
States.Add(new State() { StateID = 92, CountryID = 3, StateName = "Guinea, Republic of" });
States.Add(new State() { StateID = 93, CountryID = 3, StateName = "Guinea-Bissau, Republic of" });
States.Add(new State() { StateID = 94, CountryID = 6, StateName = "Guyana, Co-operative Republicof" });
States.Add(new State() { StateID = 95, CountryID = 5, StateName = "Haiti, Republic of" });
States.Add(new State() { StateID = 96, CountryID = 7, StateName = "Heard Island and McDonald Islands" });
States.Add(new State() { StateID = 97, CountryID = 2, StateName = "Holy See (Vatican City State)" });
States.Add(new State() { StateID = 98, CountryID = 5, StateName = "Honduras, Republic of" });
States.Add(new State() { StateID = 99, CountryID = 1, StateName = "Hong Kong, Special Administrative Region of China" });
States.Add(new State() { StateID = 100, CountryID = 2, StateName = "Hungary, Republic of" });
States.Add(new State() { StateID = 101, CountryID = 2, StateName = "Iceland, Republic of" });
States.Add(new State() { StateID = 102, CountryID = 1, StateName = "India, Republic of" });
States.Add(new State() { StateID = 103, CountryID = 1, StateName = "Indonesia, Republic of" });
States.Add(new State() { StateID = 104, CountryID = 1, StateName = "Iran, Islamic Republic of" });
States.Add(new State() { StateID = 105, CountryID = 1, StateName = "Iraq, Republic of" });
States.Add(new State() { StateID = 106, CountryID = 2, StateName = "Ireland" });
States.Add(new State() { StateID = 107, CountryID = 2, StateName = "Isle of Man" });
States.Add(new State() { StateID = 108, CountryID = 1, StateName = "Israel, State of" });
States.Add(new State() { StateID = 109, CountryID = 2, StateName = "Italy, Italian Republic" });
States.Add(new State() { StateID = 110, CountryID = 5, StateName = "Jamaica" });
States.Add(new State() { StateID = 111, CountryID = 1, StateName = "Japan" });
States.Add(new State() { StateID = 112, CountryID = 2, StateName = "Jersey, Bailiwick of" });
States.Add(new State() { StateID = 113, CountryID = 1, StateName = "Jordan, Hashemite Kingdom of" });
States.Add(new State() { StateID = 114, CountryID = 1, StateName = "Kazakhstan, Republic of" });
States.Add(new State() { StateID = 115, CountryID = 3, StateName = "Kenya, Republic of" });
States.Add(new State() { StateID = 116, CountryID = 4, StateName = "Kiribati, Republic of" });
States.Add(new State() { StateID = 117, CountryID = 1, StateName = "Korea, Democratic People's Republic of" });
States.Add(new State() { StateID = 118, CountryID = 1, StateName = "Korea, Republic of" });
States.Add(new State() { StateID = 119, CountryID = 1, StateName = "Kuwait, State of" });
States.Add(new State() { StateID = 120, CountryID = 1, StateName = "Kyrgyz Republic" });
States.Add(new State() { StateID = 121, CountryID = 1, StateName = "Lao People's Democratic Republic" });
States.Add(new State() { StateID = 122, CountryID = 2, StateName = "Latvia, Republic of" });
States.Add(new State() { StateID = 123, CountryID = 1, StateName = "Lebanon, Lebanese Republic" });
States.Add(new State() { StateID = 124, CountryID = 3, StateName = "Lesotho, Kingdom of" });
States.Add(new State() { StateID = 125, CountryID = 3, StateName = "Liberia, Republic of" });
States.Add(new State() { StateID = 126, CountryID = 3, StateName = "Libyan Arab Jamahiriya" });
States.Add(new State() { StateID = 127, CountryID = 2, StateName = "Liechtenstein, Principality of" });
States.Add(new State() { StateID = 128, CountryID = 2, StateName = "Lithuania, Republic of" });
States.Add(new State() { StateID = 129, CountryID = 2, StateName = "Luxembourg, Grand Duchy of" });
States.Add(new State() { StateID = 130, CountryID = 1, StateName = "Macao, Special AdministrativeRegion of China" });
States.Add(new State() { StateID = 131, CountryID = 2, StateName = "Macedonia, Republic of" });
States.Add(new State() { StateID = 132, CountryID = 3, StateName = "Madagascar, Republic of" });
States.Add(new State() { StateID = 133, CountryID = 3, StateName = "Malawi, Republic of" });
States.Add(new State() { StateID = 134, CountryID = 1, StateName = "Malaysia" });
States.Add(new State() { StateID = 135, CountryID = 1, StateName = "Maldives, Republic of" });
States.Add(new State() { StateID = 136, CountryID = 3, StateName = "Mali, Republic of" });
States.Add(new State() { StateID = 137, CountryID = 2, StateName = "Malta, Republic of" });
States.Add(new State() { StateID = 138, CountryID = 4, StateName = "Marshall Islands, Republic ofthe" });
States.Add(new State() { StateID = 139, CountryID = 5, StateName = "Martinique" });
States.Add(new State() { StateID = 140, CountryID = 3, StateName = "Mauritania, Islamic Republicof" });
States.Add(new State() { StateID = 141, CountryID = 3, StateName = "Mauritius, Republic of" });
States.Add(new State() { StateID = 142, CountryID = 3, StateName = "Mayotte" });
States.Add(new State() { StateID = 143, CountryID = 5, StateName = "Mexico, United Mexican States" });
States.Add(new State() { StateID = 144, CountryID = 4, StateName = "Micronesia, Federated Statesof" });
States.Add(new State() { StateID = 145, CountryID = 2, StateName = "Moldova, Republic of" });
States.Add(new State() { StateID = 146, CountryID = 2, StateName = "Monaco, Principality of" });
States.Add(new State() { StateID = 147, CountryID = 1, StateName = "Mongolia" });
States.Add(new State() { StateID = 148, CountryID = 2, StateName = "Montenegro, Republic of" });
States.Add(new State() { StateID = 149, CountryID = 5, StateName = "Montserrat" });
States.Add(new State() { StateID = 150, CountryID = 3, StateName = "Morocco, Kingdom of" });
States.Add(new State() { StateID = 151, CountryID = 3, StateName = "Mozambique, Republic of" });
States.Add(new State() { StateID = 152, CountryID = 1, StateName = "Myanmar, Union of" });
States.Add(new State() { StateID = 153, CountryID = 3, StateName = "Namibia, Republic of" });
States.Add(new State() { StateID = 154, CountryID = 4, StateName = "Nauru, Republic of" });
States.Add(new State() { StateID = 155, CountryID = 1, StateName = "Nepal, State of" });
States.Add(new State() { StateID = 156, CountryID = 5, StateName = "Netherlands Antilles" });
States.Add(new State() { StateID = 157, CountryID = 2, StateName = "Netherlands, Kingdom of the" });
States.Add(new State() { StateID = 158, CountryID = 4, StateName = "New Caledonia" });
States.Add(new State() { StateID = 159, CountryID = 4, StateName = "New Zealand" });
States.Add(new State() { StateID = 160, CountryID = 5, StateName = "Nicaragua, Republic of" });
States.Add(new State() { StateID = 161, CountryID = 3, StateName = "Niger, Republic of" });
States.Add(new State() { StateID = 162, CountryID = 3, StateName = "Nigeria, Federal Republic of" });
States.Add(new State() { StateID = 163, CountryID = 4, StateName = "Niue" });
States.Add(new State() { StateID = 164, CountryID = 4, StateName = "Norfolk Island" });
States.Add(new State() { StateID = 165, CountryID = 4, StateName = "Northern Mariana Islands, Commonwealth of the" });
States.Add(new State() { StateID = 166, CountryID = 2, StateName = "Norway, Kingdom of" });
States.Add(new State() { StateID = 167, CountryID = 1, StateName = "Oman, Sultanate of" });
States.Add(new State() { StateID = 168, CountryID = 1, StateName = "Pakistan, Islamic Republic of" });
States.Add(new State() { StateID = 169, CountryID = 4, StateName = "Palau, Republic of" });
States.Add(new State() { StateID = 170, CountryID = 1, StateName = "Palestinian Territory, Occupied" });
States.Add(new State() { StateID = 171, CountryID = 5, StateName = "Panama, Republic of" });
States.Add(new State() { StateID = 172, CountryID = 4, StateName = "Papua New Guinea, IndependentState of" });
States.Add(new State() { StateID = 173, CountryID = 6, StateName = "Paraguay, Republic of" });
States.Add(new State() { StateID = 174, CountryID = 6, StateName = "Peru, Republic of" });
States.Add(new State() { StateID = 175, CountryID = 1, StateName = "Philippines, Republic of the" });
States.Add(new State() { StateID = 176, CountryID = 4, StateName = "Pitcairn Islands" });
States.Add(new State() { StateID = 177, CountryID = 2, StateName = "Poland, Republic of" });
States.Add(new State() { StateID = 178, CountryID = 2, StateName = "Portugal, Portuguese Republic" });
States.Add(new State() { StateID = 179, CountryID = 5, StateName = "Puerto Rico, Commonwealth of" });
States.Add(new State() { StateID = 180, CountryID = 1, StateName = "Qatar, State of" });
States.Add(new State() { StateID = 181, CountryID = 3, StateName = "Reunion" });
States.Add(new State() { StateID = 182, CountryID = 2, StateName = "Romania" });
States.Add(new State() { StateID = 183, CountryID = 2, StateName = "Russian Federation" });
States.Add(new State() { StateID = 184, CountryID = 3, StateName = "Rwanda, Republic of" });
States.Add(new State() { StateID = 185, CountryID = 5, StateName = "Saint Barthelemy" });
States.Add(new State() { StateID = 186, CountryID = 3, StateName = "Saint Helena" });
States.Add(new State() { StateID = 187, CountryID = 5, StateName = "Saint Kitts and Nevis, Federation of" });
States.Add(new State() { StateID = 188, CountryID = 5, StateName = "Saint Lucia" });
States.Add(new State() { StateID = 189, CountryID = 5, StateName = "Saint Martin" });
States.Add(new State() { StateID = 190, CountryID = 5, StateName = "Saint Pierre and Miquelon" });
States.Add(new State() { StateID = 191, CountryID = 5, StateName = "Saint Vincent and the Grenadines" });
States.Add(new State() { StateID = 192, CountryID = 4, StateName = "Samoa, Independent State of" });
States.Add(new State() { StateID = 193, CountryID = 2, StateName = "San Marino, Republic of" });
States.Add(new State() { StateID = 194, CountryID = 3, StateName = "Sao Tome and Principe, Democratic Republic of" });
States.Add(new State() { StateID = 195, CountryID = 1, StateName = "Saudi Arabia, Kingdom of" });
States.Add(new State() { StateID = 196, CountryID = 3, StateName = "Senegal, Republic of" });
States.Add(new State() { StateID = 197, CountryID = 2, StateName = "Serbia, Republic of" });
States.Add(new State() { StateID = 198, CountryID = 3, StateName = "Seychelles, Republic of" });
States.Add(new State() { StateID = 199, CountryID = 3, StateName = "Sierra Leone, Republic of" });
States.Add(new State() { StateID = 200, CountryID = 1, StateName = "Singapore, Republic of" });
States.Add(new State() { StateID = 201, CountryID = 2, StateName = "Slovakia (Slovak Republic)" });
States.Add(new State() { StateID = 202, CountryID = 2, StateName = "Slovenia, Republic of" });
States.Add(new State() { StateID = 203, CountryID = 4, StateName = "Solomon Islands" });
States.Add(new State() { StateID = 204, CountryID = 3, StateName = "Somalia, Somali Republic" });
States.Add(new State() { StateID = 205, CountryID = 3, StateName = "South Africa, Republic of" });
States.Add(new State() { StateID = 206, CountryID = 7, StateName = "South Georgia and the South Sandwich Islands" });
States.Add(new State() { StateID = 207, CountryID = 2, StateName = "Spain, Kingdom of" });
States.Add(new State() { StateID = 208, CountryID = 1, StateName = "Sri Lanka, Democratic Socialist Republic of" });
States.Add(new State() { StateID = 209, CountryID = 3, StateName = "Sudan, Republic of" });
States.Add(new State() { StateID = 210, CountryID = 6, StateName = "Suriname, Republic of" });
States.Add(new State() { StateID = 211, CountryID = 2, StateName = "Svalbard & Jan Mayen Islands" });
States.Add(new State() { StateID = 212, CountryID = 3, StateName = "Swaziland, Kingdom of" });
States.Add(new State() { StateID = 213, CountryID = 2, StateName = "Sweden, Kingdom of" });
States.Add(new State() { StateID = 214, CountryID = 2, StateName = "Switzerland, Swiss Confederation" });
States.Add(new State() { StateID = 215, CountryID = 1, StateName = "Syrian Arab Republic" });
States.Add(new State() { StateID = 216, CountryID = 1, StateName = "Taiwan" });
States.Add(new State() { StateID = 217, CountryID = 1, StateName = "Tajikistan, Republic of" });
States.Add(new State() { StateID = 218, CountryID = 3, StateName = "Tanzania, United Republic of" });
States.Add(new State() { StateID = 219, CountryID = 1, StateName = "Thailand, Kingdom of" });
States.Add(new State() { StateID = 220, CountryID = 1, StateName = "Timor-Leste, Democratic Republic of" });
States.Add(new State() { StateID = 221, CountryID = 3, StateName = "Togo, Togolese Republic" });
States.Add(new State() { StateID = 222, CountryID = 4, StateName = "Tokelau" });
States.Add(new State() { StateID = 223, CountryID = 4, StateName = "Tonga, Kingdom of" });
States.Add(new State() { StateID = 224, CountryID = 5, StateName = "Trinidad and Tobago, Republicof" });
States.Add(new State() { StateID = 225, CountryID = 3, StateName = "Tunisia, Tunisian Republic" });
States.Add(new State() { StateID = 226, CountryID = 1, StateName = "Turkey, Republic of" });
States.Add(new State() { StateID = 227, CountryID = 1, StateName = "Turkmenistan" });
States.Add(new State() { StateID = 228, CountryID = 5, StateName = "Turks and Caicos Islands" });
States.Add(new State() { StateID = 229, CountryID = 4, StateName = "Tuvalu" });
States.Add(new State() { StateID = 230, CountryID = 3, StateName = "Uganda, Republic of" });
States.Add(new State() { StateID = 231, CountryID = 2, StateName = "Ukraine" });
States.Add(new State() { StateID = 232, CountryID = 1, StateName = "United Arab Emirates" });
States.Add(new State() { StateID = 233, CountryID = 2, StateName = "United Kingdom of Great Britain & Northern Ireland" });
States.Add(new State() { StateID = 234, CountryID = 5, StateName = "United States of America" });
States.Add(new State() { StateID = 235, CountryID = 4, StateName = "United States Minor OutlyingIslands" });
States.Add(new State() { StateID = 236, CountryID = 5, StateName = "United States Virgin Islands" });
States.Add(new State() { StateID = 237, CountryID = 6, StateName = "Uruguay, Eastern Republic of" });
States.Add(new State() { StateID = 238, CountryID = 1, StateName = "Uzbekistan, Republic of" });
States.Add(new State() { StateID = 239, CountryID = 4, StateName = "Vanuatu, Republic of" });
States.Add(new State() { StateID = 240, CountryID = 6, StateName = "Venezuela, Bolivarian Republic of" });
States.Add(new State() { StateID = 241, CountryID = 1, StateName = "Vietnam, Socialist Republic of" });
States.Add(new State() { StateID = 242, CountryID = 4, StateName = "Wallis and Futuna" });
States.Add(new State() { StateID = 243, CountryID = 3, StateName = "Western Sahara" });
States.Add(new State() { StateID = 244, CountryID = 1, StateName = "Yemen" });
States.Add(new State() { StateID = 245, CountryID = 3, StateName = "Zambia, Republic of" });
States.Add(new State() { StateID = 246, CountryID = 3, StateName = "Zimbabwe, Republic of" });
}
}
#endregion
}
My VIEW Looks Like this (CustomerView.XAML):
<UserControl x:Class="SilverlightWithWCFService.View.CustomerView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:View="clr-namespace:SilverlightWithWCFService.Model"
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
d:DesignHeight="300" d:DesignWidth="400">
<UserControl.DataContext>
<View:CustomerViewModel />
</UserControl.DataContext>
<UserControl.Resources>
<View:CustomerViewModel x:Key="MyViewModel" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="400" />
<RowDefinition Height="50" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<telerik:RadGridView x:Name="CustomerGrid" AutoGenerateColumns="False" Grid.Row="0" ItemsSource="{Binding objSearchList}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding CustomerID,Mode=TwoWay}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding CompanyName,Mode=TwoWay}" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding ContactName,Mode=TwoWay}" />
<telerik:GridViewComboBoxColumn
DataMemberBinding="{Binding Country,Mode=TwoWay}"
Header="Country"
DisplayMemberPath="CountryName" SelectedValueMemberPath="CountryID"
ItemsSourceBinding="{Binding CountryList, Source={StaticResource MyViewModel}}" />
<telerik:GridViewComboBoxColumn
DataMemberBinding="{Binding State,Mode=TwoWay}"
Header="State"
DisplayMemberPath="StateName" SelectedValueMemberPath="StateID"
ItemsSourceBinding="{Binding StateList, Source={StaticResource MyViewModel}}"
/>
<!--<telerik:GridViewComboBoxColumn ItemsSourceBinding="{Binding AvailableState}" DataMemberBinding="{Binding State}" Header="State" DisplayMemberPath="StateName" SelectedValueMemberPath="StateID" />-->
<!--<telerik:GridViewComboBoxColumn ItemsSourceBinding="{Binding AvailableState}" DataMemberBinding="{Binding State}" Header="State" DisplayMemberPath="StateName" SelectedValueMemberPath="StateID" />-->
</telerik:RadGridView.Columns>
</telerik:RadGridView>
<Button Grid.Row="1" Height="25" Width="50" HorizontalAlignment="Center" Content="Add" Click="Button_Click" />
</Grid>
</UserControl>
My VIEW .CS Looks Like this (CustomerView.XAML.CS):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using SilverlightWithWCFService.Model;
using Telerik.Windows.Controls;
using Telerik.Windows;
namespace SilverlightWithWCFService.View
{
public partial class CustomerView : UserControl
{
CustomerViewModel cvm = new CustomerViewModel();
public CustomerView()
{
InitializeComponent();
this.AddHandler(RadComboBox.SelectionChangedEvent, new Telerik.Windows.Controls.SelectionChangedEventHandler(comboSelectionChanged));
}
void comboSelectionChanged(object sender, RadRoutedEventArgs args)
{
RadComboBox comboBox = (RadComboBox)args.OriginalSource;
if (comboBox.SelectedValue == null || comboBox.SelectedValuePath != "CountryID")
{
return;
}
CustromerList custList = comboBox.DataContext as CustromerList;
custList.Country = (Int32)comboBox.SelectedValue;
cvm.CID = custList.Country;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
}
}
}