Information related to conditional binding

Namespace: Dapfor.Net.Ui
Assembly: Dapfor.Net (in Dapfor.Net.dll) Version: 2.10.3.24917 (2.10.3.24917)

Syntax

C#
public sealed class GridRowAddingEventArgs : EventArgs
Visual Basic
Public NotInheritable Class GridRowAddingEventArgs
	Inherits EventArgs
Visual C++
public ref class GridRowAddingEventArgs sealed : public EventArgs
F#
[<SealedAttribute>]
type GridRowAddingEventArgs =  
    class
        inherit EventArgs
    end

Remarks

Conditional binding is one of the most powerful and convenient types of binding. It is an API provided by the grid that enables the programmer to specify insertion method when a data object is added to the grid. The API is implemented as an event that is called when data is added to the grid.

This event contains a reference to the added object, a parent row if any and insertion method for this object. Below is the list of possible actions upon data insertion to the grid:

  • AsChild - regular method of data object insertion to parent. A programmer may replace the inserted object with any other object on his own discretion.
  • AsCollection - a programmer may replace a data object with any collection that shall be added instead of the specified object.
  • AsChildAndCollection - the grid adds a data object and a new collection. The data object is added to the specified parent as with AsChild, and the collection is added on the next hierarchy level to the data object that has just been added.
  • Skip - the data object is not added to the grid.

It is important to note that if a collection implements IBindingList interface, the grid subscribes to events of this collection and inserts or modifies data on corresponding hierarchy level of the grid. All binding list operations are thread safe.

Examples

 Copy imageCopy
//Basket class
public class Basket 
{
    //Private fields
    private readonly BindingList<Order> _orders = new BindingList<Order>();

    //Public properties    
    public IList<Order> Orders
    {
        get { return _orders; }
    }
}

//Initialize the grid
public void InitializeGrid(Grid grid, IList<Basket> baskets)
{
    grid.RowAdding += OnGridRowAdding;

    //Bind the grid to basket collection
    grid.DataSource = baskets;
}


private void OnGridRowAdding(object sender, GridRowAddingEventArgs e)
{
    //Skip the 'basket' level and bind orders directly to basket's parent
    Basket basket = e.DataObject as Basket;
    if (basket != null)
    {
         e.DataObject = basket.Orders;
         e.InsertionType = InsertionType.AsCollection;
    }
}

Inheritance Hierarchy

System..::..Object
  System..::..EventArgs
    Dapfor.Net.Ui..::..GridRowAddingEventArgs

See Also