Event-driven model implies that grid objects implement INotifyPropertyChanged interface and use it to notify subscribers about changes inside the object. Therefore, when a setter is called in a data object, the grid gets all the required information and makes all necessary actions. If you need to change value in a data object from the grid, you can use Cell.Value property.

C# Copy imageCopy
//Some data object
class Product : INotifyPropertyChanged
{
    private double price;

    public double Price
    {
        get { return price; }
        set
        {
            price = value;
            if(PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Price"));
            }
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
}



public void CellValue(Grid grid)
{
    Product product = new Product();
    grid.Rows.Add(product);
    Row row = grid.Rows[0];

    product.Price = 12.65;
    Console.WriteLine("Price of the product = {0}", product.Price);
    Console.WriteLine("Value in in DataDbject: {0}", ((Product)row.DataObject).Price);
    Console.WriteLine("Value in in DataAccessor: {0}", row.DataAccessor["Price"].Value);
    Console.WriteLine("Value in Cell: {0}", row["Price"].Value);

    row["Price"].Value = 13.44;
    Console.WriteLine("Updated price of the product = {0}", product.Price);
}  

//Output:
//Price of the product = 12,65
//Value in in DataDbject: 12,65
//Value in in DataAccessor: 12,65
//Value in Cell: 12,65
//Updated price of the product = 13,44

Back to .Net Grid HowTo topics