Contains a collection of Cells and information about data object, its location, hierarchy in the data grid, color, etc.

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 Row
Visual Basic
Public NotInheritable Class Row
Visual C++
public ref class Row sealed
F#
[<SealedAttribute>]
type Row =  class end

Remarks

Data can be added into the grid via Grid.Rows.Add(object dataObject) method call. This method returns object of Row type. To build a hierarchy, it is enough to call the Row.Add(object) method, which in turn returns a new Row object. This way a programmer can build almost any hierarchy in the .Net Grid. All headers and rows have their own zero-based hierarchical level that is defined by Header.Level and Row.Level properties. To display data in every row, .Net Grid takes header of the same level as that row. However, if that level doesn't have a header, the header for the previous hierarchical level is used. In other words, if only one header is present, the grid will behave like Microsoft Windows Explorer.

.Net Grid supports many data types because of the IDataAccessor interface that is one of the most crucial part of the grid. The main purpose of this interface is to normalize presentation of different data types in the grid. There are lots of implementations of IDataAccessor interface. This way, a programmer can add his own implementation to broaden the list of data types that can be used by the .Net Grid. When you call Grid.Rows.Add('your object'), an implementation of the IDataAccessor interface is created implicitly for 'your object' and the .Net Grid works with it only via the IDataAccessor proxy, making no difference between the data types.

For different objects the process of getting or setting values of a data object may vary. For user-defined classes you can use the reflection mechanism to get or set values. For IList<T> the grid gets them with a certain index; for IDictionary<string, object> with a string key so on. IDataAccessor may support or not support data field identifiers it merely depends on its nature. If an object of user defined class is inserted into the grid, than its property name become the identifiers in the IDataAccessor by default. However, sometimes identifiers may be absent, e.g. if you you use an IList<T> object as a parameter of the method Grid.Rows.Add('your object'). In such case, to display data in cells the .Net Grid uses indices of IList<T> and index of the column which is calculated when it is inserted into the header.

 Copy imageCopy
//Some data object
public class Product : INotifyPropertyChanged
{
    //Some fields
    private double price;
    private DateTime maturity;

    [DoubleFormat(Precision = 3, ShortForm = true, ShowZero = false)]
    public double Price
    {
        get { return price; }
        set
        {
            price = value;
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Price"));
            }
        }
    }

    public DateTime Maturity
    {
        get { return maturity; }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}

//Using sample
public void PopulateGridWithDataObjects(Grid grid)
{
    //Initialize the grid
    grid.Headers.Add(new Header());
    grid.Headers[0].Add(new Column("Price"));
    grid.Headers[0].Add(new Column("Maturity"));

    grid.Headers.Add(new Header());
    grid.Headers[1].Add(new Column("FirstName"));
    grid.Headers[1].Add(new Column("SecondName"));


    //Add data object to the grid. The object will be implicitly wrapped by the DataObjectAccessor class
    Product product = new Product();
    Row productRow = grid.Rows.Add(product);

    //Build some hierarchy ()...
    productRow.Add(new Customer("John", "Smith"));

    //Or from another thread - this is safe.
    ThreadPool.QueueUserWorkItem(delegate
    {
        productRow.Add(new Customer("Sherlock", "Holmes"));
    });

    //This call will notify the grid through the INotifyPropertyChanged
    //The grid will automatically repaint affected cells, and also sort and filter the row.
    product.Price = 12.36;

    //Or from another thread - this is safe.
    ThreadPool.QueueUserWorkItem(delegate
    {
        product.Price = 14.21;
    });
}

Inheritance Hierarchy

System..::..Object
  Dapfor.Net.Ui..::..Row

Thread Safety

If needed, the Row synchronizes the calling thread with the GUI without blocking the calling thread.

See Also