none
How to add items to a ListView dynamically in WPF?

    Question

  • I want to realize a listview, in which each row represents a user. And the listview will have the following columns:

    Column 1: an image, the portraitof a user.
    Column 2: an image, whether to be appear depends on whether the user has a camera.
    Column 3: an image to declare the level of the user.
    Column 4: a string corresponds to the id of the user.
    Column 5: a button to change the level of the user.

    Then, in the corresponding csharp code, I want to add users dynamically, which means I don't know what to add till I receive some message from the Internet.

    I have referred to the samples in MSDN, but cannot find any sample that can add items dynamically. Can anybody help me with this problem? If there are some samples, that would be better.
    Friday, June 19, 2009 6:33 AM

Answers

  • Hi,

    Think you can create an entity to hold the user details.Then you can bind the list view columns to each of the property.
    For the button you will have to change the data template.

    After creating the object dynamically just add it to the listview items.

    See this link for a sample

    Hope it helps
    FEAR NOT TO BE JUST Please mark posts as answers/helpful if it answers your query
    Friday, June 19, 2009 7:12 AM