Paperwaste
Paperwaste

Reputation: 685

Can i set the contents of ListView?

I have a data model that has a few nested lists and i would like to use ListViews to show them because i like having the details in the list.

eg data Model

public class EventModel
{
    public List<EndPointType> Targets { get; set; }
    public string EventTime { get; set; }
    public DataEvent EventMessage { get; set; }
}

public class EndPointType
{
    public int Type;
    public List<EndPoint> Displays {get; set;}
}

public class EndPoint
{
    public string DisplayName { get; set; }
    public string DisplayCode { get; set; }
}

I wish to keep a list of EventModel in one ListView I know how to do this with tags and sub items.

My question is when a selection is made of an EventModel from the list is it possible a second ListView updates its Items to reflect the List<EndPointType> of the selected EventModel

TL;DR Can you set the entire contents of a ListView similar to using ListBox.Datasource?

Upvotes: 1

Views: 59

Answers (1)

Milan Halada
Milan Halada

Reputation: 1934

Edit: for winforms... Try something like this for SelectionChanged event:

private void list_SelectedIndexChanged(object sender, EventArgs e)
{
    var eModel = (EventModel)((ListView)sender).SelectedItem;

    var targets = GetEndPointTypesFromList(eModel);
    listView1.Items.Clear();
    foreach(var target in targets)
    {
        listview.Items.Add(target.Type.ToString());
    }

}

Upvotes: 1

Related Questions