目的是将列表视为“名称”列表。
这是字典:
class Scripts
{
public Dictionary<int, Script> scripts = new Dictionary<int, Script>();
...
}
这是我所追求的属性“名称”:
class Script
{
public string name { get; set; }
...
}
这就是问题所在:
public partial class MainForm : Form
{
Scripts allScripts;
public MainForm()
{
InitializeComponent();
allScripts = new Scripts();
setupDataSources();
}
private void setupDataSources()
{
BindingSource ketchup = new BindingSource(allScripts.scripts, null);
//THIS LINE:
listBoxScripts.DisplayMember = allScripts.scripts["Key"].name.ToString();
listBoxScripts.ValueMember = "Key";
listBoxScripts.DataSource = ketchup;
}
...
}
我只是想不出如何使这条线工作!非常感谢您的建议!
谢谢