0

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?

1
  • 2
    WPF? WinForms? ASP.Net? Silverlight? MonoTouch? Commented Jun 22, 2011 at 14:37

1 Answer 1

1

Try the following:

listView1.Items.AddRange
    (
        (
            from c in classList
            where c.Status = 1
            select new ListViewItem(c.Text1 + c.Text2, c.Text3)
        ).ToArray()
    );
Sign up to request clarification or add additional context in comments.

8 Comments

Yes, except that class is a keyword.
ListView doesn't have a DataSource member.
@Jonnster: Yes it does. Check ListView Class
I'm not using the web control. I am using the windows forms control. So no it doesn't. msdn.microsoft.com/en-us/library/…
Thanks but that won't build. The error is Error 1 Could not find an implementation of the query pattern for source type MyListClass'. 'Where' not found.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.