我已經創建了一個列表框,在其內應該有多個選擇,通過選擇選項中的一個有將顯示所選擇的選擇描述在標籤,這從選擇分化爲選擇列表框多個選擇不同的描述錯誤
我想出了這個代碼:
public Form1()
{
InitializeComponent();
listBox1.DataSource = choices;
listBox1.DisplayMember = "name";
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = valikud.ElementAt(listBox1.SelectedIndex).description;
}
List<dynamic> choices = new List<dynamic>()
{
new {
name = "Choice 1",
description = "Description 1"
},
new {
name = "Choice 2",
description = "Description 2"
}
};
}
}
這個工作經常形式,問題就來了,當我加入這個到我的其他程序到user control
,發生在這個問題:
List<*dynamic*> choices = new List<dynamic>()
的錯誤狀態:
錯誤CS1980無法定義,其利用「動態」,因爲編譯器所需的類型「System.Runtime.CompilerServices.DynamicAttribute」不能找到類或構件。你錯過了一個參考嗎?
UPDATE:這個問題是由於我的過時的.NET Framework版本,我更新到4.6時,它是3.0
但是現在在這之前造成了新的問題,就是在:
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = *choices.ElementAt(listBox1.SelectedIndex)*.description;
}
錯誤狀態:
錯誤CS0656缺失編譯器所需部件 'Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo.Create'
我該如何解決這個問題? - 感謝
我認爲這是項目所針對的框架的問題。該項目的框架版本是什麼? –
@ChetanRanpariya 3.5我認爲 – Winter