Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try using a BindingList&lt;> instead of List&lt;> and (as already suggested by Daniel), implement INotifyPropertyChanged. However, I think you can also call .Refesh() if you didn't want to implement the INotifyPropertyChanged interface.</p> <p>Here's an example ripped from <a href="http://www.switchonthecode.com/tutorials/csharp-tutorial-binding-a-datagridview-to-a-collection" rel="noreferrer">here</a></p> <pre><code>public class Car : INotifyPropertyChanged { private string _make; private string _model; private int _year; public event PropertyChangedEventHandler PropertyChanged; public Car(string make, string model, int year) { _make = make; _model = model; _year = year; } public string Make { get { return _make; } set { _make = value; this.NotifyPropertyChanged("Make"); } } public string Model { get { return _model; } set { _model = value; this.NotifyPropertyChanged("Model"); } } public int Year { get { return _year; } set { _year = value; this.NotifyPropertyChanged("Year"); } } private void NotifyPropertyChanged(string name) { if(PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(name)); } } _dgCars.AutoGenerateColumns = false; DataGridViewTextBoxColumn makeColumn = new DataGridViewTextBoxColumn(); makeColumn.DataPropertyName = "Make"; makeColumn.HeaderText = "The Car's Make"; DataGridViewTextBoxColumn modelColumn = new DataGridViewTextBoxColumn(); modelColumn.DataPropertyName = "Model"; modelColumn.HeaderText = "The Car's Model"; DataGridViewTextBoxColumn yearColumn = new DataGridViewTextBoxColumn(); yearColumn.DataPropertyName = "Year"; yearColumn.HeaderText = "The Car's Year"; _dgCars.Columns.Add(makeColumn); _dgCars.Columns.Add(modelColumn); _dgCars.Columns.Add(yearColumn); BindingList&lt;Car&gt; cars = new BindingList&lt;Car&gt;(); cars.Add(new Car("Ford", "Mustang", 1967)); cars.Add(new Car("Shelby AC", "Cobra", 1965)); cars.Add(new Car("Chevrolet", "Corvette Sting Ray", 1965)); _dgCars.DataSource = cars; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload