views:

15

answers:

1

Hi guys.

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 ToolStripCombobox. What am I doing wrong?

A: 

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;
    }
 }
msergeant