首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将结构数组绑定到ToolStripCombobox

将结构数组绑定到ToolStripCombobox
EN

Stack Overflow用户
提问于 2010-07-08 02:48:31
回答 1查看 480关注 0票数 0

我尝试将结构数组绑定到ToolStripCombobox,但没有成功。

我试着像在this示例中一样使用它,但是当我试图设置一个值成员时,我得到了错误。

我的代码如下所示:

代码语言:javascript
复制
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)};

和实际的绑定代码:

代码语言:javascript
复制
        cbxTimes.ComboBox.DataSource = PlayTimeLengths;
        cbxTimes.ComboBox.DisplayMember = "Description";
        cbxTimes.ComboBox.ValueMember = "Seconds"; //<-- exception here

cbxTimes的类型为ToolStripCombobox。我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-07-08 03:12:59

您的成员应该是属性才能进行绑定。

代码语言:javascript
复制
private string description;
public string Description
{
    get
    {
       return description;
    }
    set
    {
       description = value;
    }
}
private double seconds;
public double Seconds
{
    get
    {
       return seconds;
    }
    set
    {
       seconds = value;
    }
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3197850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档