如何在C#中向组合框选择添加值?

如何在C#中向组合框选择添加值?,c#,combobox,label,box,C#,Combobox,Label,Box,所以我有两个组合框,一个依赖于另一个。我也有一个标签,我想在其中显示的价格。 我想帮助添加一个数字值到组合框选择,然后将显示在我的标签上 if (CarModelCB.Text == "Gallardo") { lblCarPrice.Text = "180000"; } 我得到了很多红线,但这大概就是我想要的样子。我会创建一个字典,它存储价格并使用CarModel名称作为键 Dictionary<string, int> prices = new Diction

所以我有两个组合框,一个依赖于另一个。我也有一个标签,我想在其中显示的价格。 我想帮助添加一个数字值到组合框选择,然后将显示在我的标签上

 if (CarModelCB.Text == "Gallardo")
 { 
     lblCarPrice.Text = "180000";
 }

我得到了很多红线,但这大概就是我想要的样子。

我会创建一个字典,它存储价格并使用CarModel名称作为键

Dictionary<string, int> prices = new Dictionary<string, int>();

prices.Add("Gallardo", 180000);

我会使用简单的数据绑定。。。 首先你需要一个这样的模型

class Car
{
    public string Model { get; set; }
    public decimal Price { get; set; }
}
注意:您可能应该实现INotifyPropertyChanged。互联网上有很多例子


然后将组合框绑定到模型并设置相关的数据成员。

您能分享一些实际代码吗?另外,您使用的是什么UI引擎?WinForms?WPF?它是WFA,这就是我试图编写的代码。我对这一点很陌生,但我正在尝试整理一家汽车经销商,其中一家CB展示品牌,另一家展示该品牌的车型。然后上面写的代码是为了表明我想做什么。字典会在Form类下声明吗?
class Car
{
    public string Model { get; set; }
    public decimal Price { get; set; }
}