I'm new to the sfDataGrid. It looks very interesting.
I looked at the demo and its code that is shipped with v16.1.0.24
I dragged the control on my form and added in my form constructor:
_order = new Order();
sfDataGrid1.DataSource = _order.OrderLines;
I use _order.OrderLines.Add(SqliteService.ProductToOrderLine(product)); to add a new row to the DataGrid.
My classes:
public class Order : IDisposable
{
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
public double TotalPrice { get; set; }
public IList<OrderLine> OrderLines { get; set; }
public Order()
{
CreatedAt = DateTime.Now;
OrderLines = new List<OrderLine>();
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool isdisposable)
{
OrderLines?.Clear();
}
}
public class OrderLine : INotifyPropertyChanged
{
private double _price;
private string _name;
private int _id;
private int _productId;
private string _barcode;
private int _amount;
[Display(AutoGenerateField = false)]
public int Id
{
get { return _id; }
set
{
if (value == _id) return;
_id = value;
OnPropertyChanged(nameof(Id));
}
}
public int ProductId
{
get { return _productId; }
set
{
if (value == _productId) return;
_productId = value;
OnPropertyChanged(nameof(ProductId));
}
}
[Display(Name = "Name")]
public string Name
{
get { return _name; }
set
{
if (value == _name) return;
_name = value;
OnPropertyChanged(nameof(Name));
}
}
[Display(Name = "Prijs")]
public double Price
{
get { return _price; }
set
{
if (value.Equals(_price)) return;
_price = value;
OnPropertyChanged(nameof(Price));
}
}
public string Barcode
{
get { return _barcode; }
set
{
if (value == _barcode) return;
_barcode = value;
OnPropertyChanged(nameof(Barcode));
}
}
[Display(Name = "Aantal")]
public int Amount
{
get { return _amount; }
set
{
if (value == _amount) return;
_amount = value;
OnPropertyChanged(nameof(Amount));
}
}
public event PropertyChangedEventHandler PropertyChanged;
[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
I tested OnPropertyChanged() and it is called.
But somehow sfDataGrid doesn't get notified.
When I sort the data the new data is shown. So the datasource is correct. It is just not updated.
What do I need to do more to tell sfDataGrid is should re-render.