我尝试将结构数组绑定到ToolStripCombobox,但没有成功。
我试着像在this示例中一样使用它,但是当我试图设置一个值成员时,我得到了错误。
我的代码如下所示:
public struct PlayTimeLength
{
public string Description;
public double Seconds;
public PlayTimeLength(string description, double seconds)
{
Description = description;
Seconds = seconds;
}
}
public PlayTimeLength[] PlayTimeLengths = {new PlayTimeLength("1 minuta", 1*60), new PlayTimeLength("3 minuty", 3*60), new PlayTimeLength("5 minut", 5*60)};和实际的绑定代码:
cbxTimes.ComboBox.DataSource = PlayTimeLengths;
cbxTimes.ComboBox.DisplayMember = "Description";
cbxTimes.ComboBox.ValueMember = "Seconds"; //<-- exception herecbxTimes的类型为ToolStripCombobox。我做错了什么?
发布于 2010-07-08 03:12:59
您的成员应该是属性才能进行绑定。
private string description;
public string Description
{
get
{
return description;
}
set
{
description = value;
}
}
private double seconds;
public double Seconds
{
get
{
return seconds;
}
set
{
seconds = value;
}
}https://stackoverflow.com/questions/3197850
复制相似问题