开发者

How to add next column to ListBox while using DataSource?

Let's say I have a ListBox called animalList. As DataSource I use following class:

class Animal
{
    private int id;
    private string name;
    private string description;

    public Animal(int id, string name, string description)
    {
        // implementation
    }

    public int Id
    {
        // implementation
    }

    public string Name
    {
        // implementation
    }

    public string Description
    {
        // implementation
    }
}

I'd like to have 2 columns in ListBox: Name and Description. Is it possible to do so? I managed to add one column like this:

List<Animal> animals = // LINQ sucking data from XML

animalList.MultiColumn = true;
animalLis开发者_如何学运维t.DataSource = animals;
animalList.DisplayMember = "Name";
animalList.ValueMember = "Id";

but I cannot really figure out how to actually implement next column.


The name of the MultiColumn property can be slightly misleading. The ListBox control does not support the type of columns you're looking for.

What MultiColumn actually does is "overflow" items into a new column instead of showing a vertical scrollbar.

http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.multicolumn.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜