C#学习笔记——关于ListBox的Text、Name、Tag等属性添加

                                                          ListBox 和Combox的item 可以是任意的object,所以楼主可以定义自己的class来实现其他属性。比如:

1
2
3
4
5
6
7
8
9
10
11
public class ComboxItem
    {
        public string Name { getset; }
        public string Tag { getset; }
        public string Text { getset; }
 
        public override string ToString()
        {
            return Text;
        }
    }



                                                                          然后加到Combox上:

1
2
3
4
5
 ComboxItem item = new ComboxItem();
            item.Name = "Name";
            item.Tag = "Tag";
            item.Text = "Text";
            comboBox1.Items.Add(item);
posted @ 2021-06-02 19:56  vv彭  阅读(523)  评论(0编辑  收藏  举报