Jonnster
Jonnster

Reputation: 3214

Map Data From Array To ListView

I have an array of objects that I want to display in a ListView. Not all data in each object will be displayed. What is the best way of doing this considering I will want to filter which records are displayed (depending on a status flag) and easy way to update columns in the listview on the fly.

The data in the array will look something like (simplified). It doesn't have to be an array though. If there is a better option then that's fine.

class MyClass
{
    public string Text1;
    public string Text2;
    public string Text3;
    public int Status;
}

There will be other methods and properties in the class but this is what will be displayed.

Also, I will need to update this data/listview from a worker thread. What is the best way to do this?

Upvotes: 0

Views: 991

Answers (1)

Akram Shahda
Akram Shahda

Reputation: 14781

Try the following:

listView1.Items.AddRange
    (
        (
            from c in classList
            where c.Status = 1
            select new ListViewItem(c.Text1 + c.Text2, c.Text3)
        ).ToArray()
    );

Upvotes: 1

Related Questions