Note that there are some explanatory texts on larger screens.

plurals
  1. POXtraGrid binding over complex and nested objects model
    primarykey
    data
    text
    <p>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:</p> <pre><code> public class Customer { public Int32 CustomerId { get; set; } public String Name { get; set; } public String Address { get; set; } public List&lt;Order&gt; 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; } } </code></pre> <p>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:</p> <pre><code>//List of my customers private List&lt;Customer&gt; _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; } </code></pre> <p>Now i've got beautiful GridControl that shows the content of my List.</p> <p><img src="https://i.stack.imgur.com/YAnCX.png" alt="enter image description here"></p> <p>But now here's the problem...how can i add or delete row? Infact:</p> <ul> <li><p>If i set the focus on a row and i press "Delete" key, it doesn't work.</p></li> <li><p>If i try to add a new row, when it looses focus, it suddently disappears.</p></li> </ul> <p>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. </p> <p>Someone can help me?</p> <p>PS. <a href="https://dl.dropboxusercontent.com/u/60231308/SimpleBindingTest.rar" rel="nofollow noreferrer">This</a> is the hyperlink for the .csproj of my sample. </p>
    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.
 

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