选择索引更改中的labmda表达式 [英] labmda expression in select index change
本文介绍了选择索引更改中的labmda表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以上帝的名义
hi
我想用另一个组合框过滤组合框的项目
例如
其中一个包含鞋子的组合鞋和其他包括选择鞋子时的设计,与这款鞋相关的设计都来自第二个组合框>
i希望在选择索引更改中使用lambda表达式,但我不知道如何
In the name of God
hi
I want to filter item of a combo box with another combo box
for example
One of the combobox containing shoes and other including designs when choosing a shoe the designs which related to this shoe come in second combobox
i want use lambda expression in select index change but i dont know how
推荐答案
private void ComboxwithLambad_Load(object sender, EventArgs e)
{
LoadCountries();
}
public class Country
{
public int CountryId { get; set; }
public string CountryName { get; set; }
}
public class Cities
{
public int CityId { get; set; }
public string CityName { get; set; }
public int CountryId { get; set; }
}
private List<cities> GetAllCities()
{
List<cities> lstCities = new List<cities>()
{
new Cities(){ CityId=1, CityName="Banglore", CountryId=1},
new Cities(){ CityId=2, CityName="Islambad",CountryId=2},
new Cities(){ CityId=3, CityName ="Newyork",CountryId=3},
new Cities(){ CityId=4, CityName="Chennai",CountryId=1},
new Cities(){ CityId=5, CityName="New Delhi", CountryId=1},
new Cities(){ CityId=6, CityName ="Peru",CountryId=2},
new Cities(){ CityId=7, CityName="Washington D.C.",CountryId=3},
new Cities(){ CityId=8, CityName="Trivandrum", CountryId=1},
new Cities(){ CityId=9, CityName="Peshawar", CountryId=2},
new Cities(){ CityId=9, CityName="Kohat", CountryId=2}
};
return lstCities;
}
private void LoadCountries()
{
List<country> lstCountry = new List<country>()
{
new Country{ CountryId =1, CountryName="India"},
new Country{ CountryId =2, CountryName="Pakisthan"},
new Country{ CountryId =3, CountryName="USA"}
};
cbCountry.DataSource = lstCountry.ToList();
cbCountry.DisplayMember = "CountryName";
cbCountry.ValueMember = "CountryId";
}
private void cbCountry_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void cbCountry_SelectionChangeCommitted(object sender, EventArgs e)
{
List<cities> allCities = new List<cities>();
allCities = GetAllCities();
if (cbCountry.Items.Count > 0)
{
var citiesByCountry = allCities.Where(r => r.CountryId ==Convert.ToInt32(cbCountry.SelectedValue)).ToList();
cbCities.DataSource = citiesByCountry;
cbCities.DisplayMember = "CityName";
cbCities.ValueMember = "CityId";
}
}
这篇关于选择索引更改中的labmda表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文