Is it possible to bind a List to a ListView in WinForms?

后端 未结 4 529
深忆病人
深忆病人 2020-12-02 00:06

I\'d like to bind a ListView to a List. I\'m using this code:

somelistview.DataBindings.Add (\"Items\", someclass, \"SomeList\");
         


        
4条回答
  •  一整个雨季
    2020-12-02 00:29

    Alternatively, you can use DataGridView if you want data binding. Using BindingList and BindingSource will update your DataGrid when new item is added to your list.

    var barcodeContract = new BarcodeContract { Barcode = barcodeTxt.Text, Currency = currencyTxt.Text, Price = priceTxt.Text };
    
            list.Add(barcodeContract);
            var bindingList = new BindingList(list);
            var source = new BindingSource(bindingList, null);
            dataGrid.DataSource = source;
    

    And data model class

        public class BarcodeContract
    {
        public string Barcode { get; set; }
        public string Price { get; set; }
        public string Currency { get; set; }
    }
    

提交回复
热议问题