【问题标题】:Add item listbox添加项目列表框
【发布时间】:2015-09-08 19:46:27
【问题描述】:

如何在 C# 中创建一个列表框,其中项目是具有 3 个变量(2 个字符串,1 个整数)的对象?文本将是字符串之一,而值将是 1 个字符串和 1 个整数。 我在这里看到了如何使用 2 个变量进行制作: c# add object to listbox and show string of object in it

has 对象有

 class myItem
    {
        int nSomething;
        String name;
        String tMethod;

        public myItem(String name,int nSomehting,String tMethod)
        {
            this.nSomething = nSomething;
            this.name = name;
            this.tMethod = tMethod;
        }
    }

如果我设置:

listbox.DisplayMember = "name";
listbox.ValueMember = "nSomething";

我能用这个获得“tMethod”吗?

listbox.SelectedItem.tMethod

另外,当我为列表框添加项目时,我怎样才能确保它是唯一的(只是名称就足够了)?

【问题讨论】:

  • 为什么需要其他值是 int?

标签: c# visual-studio-2013 listbox


【解决方案1】:

您是否尝试过将“listbox.DataSource”与“myItem”-List 结合使用?

比你能抓到你的其他成员的项目...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 2011-10-18
    相关资源
    最近更新 更多