Associating a String Collection with ListView, Windows Forms

I have a StringCollection that I want to bind to a single ListView element. As in, a ListView should display the contents of a StringCollection. I will automatically remove items from the collection, so they do not need to interact with it through the ListView.

I have a form with a property, also →

public DRIUploadForm()
    {
        InitializeComponent();

        lvwDRIClients.DataBindings.Add("Items", this.DirtyDRIClients, "DirtyDRIClients");
    }

private StringCollection _DirtyDRIClients;
public StringCollection DirtyDRIClients 
    { 
        get
        {
            return _DirtyDRIClients;
        }
        set
        {
            _DirtyDRIClients = Settings.Default.DRIUpdates;
        }
    }
+3
source share
1 answer

ListView, . . ListBox, , , , . - ...

public partial class Form1 : Form
{
    List<Item> items = new List<Item>
    {
        new Item { Value = "One" },
        new Item { Value = "Two" },
        new Item { Value = "Three" },
    };

    public Form1()
    {
        InitializeComponent();

        listBox1.DataSource = items;
        listBox1.DisplayMember = "Value";
    }
}

public class Item
{
    public string Value { get; set; }
}
+8

Source: https://habr.com/ru/post/1756762/


All Articles