Binding array of struct to the ToolStripCombobox
I am trying to bind array of structs to the ToolStripCombobox but with no success.
I've tried to use it like in this example but I am getting error when I try to setup a value member.
My code looks like 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)};
And the actual binding code:
        cbxTimes.ComboBox.DataSource = PlayTimeLengths;
        cbxTimes.ComboBox.DisplayMember = "Description";
        cbxTimes.ComboBox.ValueMember = "Seconds"; //<-- exception here
cbxTimes is of type 开发者_JAVA技巧ToolStripCombobox. What am I doing wrong?
Your members should be properties in order to do binding.
private string description;
public string Description
{
    get
    {
       return description;
    }
    set
    {
       description = value;
    }
}
private double seconds;
public double Seconds
{
    get
    {
       return seconds;
    }
    set
    {
       seconds = value;
    }
 }
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论