I'm using a datagrid, bound to an observablecollection with TwoWay binding. My goal is, that a user generates a list of data, starting from an empty collection. So I enabled the option CanUserAddRow.
In the code, I generate the obsevrable collection with the following code:
private ObservableCollection<Ticket> idlessTicketList = new ObservableCollection<Ticket>();
The Ticket class, which the ObservableCollection consists of, looks as follows:
public class Ticket
{
public Ticket() { }
public bool ticketUsed { get; set; }
public string ticketNumber { get; set; }
public string ticketCustomer { get; set; }
public string ticketText { get; set; }
public double ticketTime { get; set; }
public Decimal ticketTypeNr { get; set; }
public string ticketTypeText { get; set; }
}
In the MainWindow Method I set the itemSource of my Datagrid to my ObservableCollection:
public MainWindow()
{
InitializeComponent();
gridIdlessTickets.ItemsSource = idlessTicketList;
}
My problem is now, that the empty row to add a new row is not displayed at startup. If I add a new row by code myGridd.Add(row), then the empty row is displayed correctly and everythings works a expected.
How must the ObservableCollection be initialized and referenced to the itemSource correctly? Where is the best place to initialize an itemSource?
Thanks in advance