I'm wondering how to solve/simplify a task that sometimes pop-ups during developement with DevExpress XtraGrid suite. Sometimes i fall into this case: Given these 2 classes that represents the model classes that comes from the Business Logic layer:
public class Customer
{
public Int32 CustomerId { get; set; }
public String Name { get; set; }
public String Address { get; set; }
public List<Order> Orders { get; set; }
}
public class Order
{
public Int32 OrderId { get; set; }
public String ItemCode { get; set; }
public Int32 Quantity { get; set; }
public Decimal Price { get; set; }
public DateTime Date { get; set; }
}
I'd like to create a simple window that shows an XtraGrid that allows edit/add/remove a list of customers and its nested orders. In order to do that, i've created a simple form with a GridControl and a GridView controls with the AllowAddRow and AllowDeleteRow properties == true. Then, in Form1 class i've done the following:
//List of my customers
private List<Customer> _customers;
public Form1()
{
//Initialize UI components
InitializeComponent();
//Call the provider in order to get customers
CustomerProvider cp = new CustomerProvider();
_customers = cp.GetCustomers();
//Initialize bindingSource
BindingSource bs = new BindingSource();
bs.DataSource = _customers;
//Set GridControl's dataSource
gridControl1.DataSource = bs;
}
Now i've got beautiful GridControl that shows the content of my List.
But now here's the problem...how can i add or delete row? Infact:
If i set the focus on a row and i press "Delete" key, it doesn't work.
If i try to add a new row, when it looses focus, it suddently disappears.
Obviously i'm missing something. Unfortunately i found the DevExpress documentation a quite confusional (in my opinion) about this kind of argument and the best practises, so i can't reach my goal.
Someone can help me?
PS. This is the hyperlink for the .csproj of my sample.