Real Time Data Update

.Net Grid enables real-time updates upon data changes. It means that when data is changed in business logic layer, the rows where this data is displayed are automatically sorted, filtrated, and grouped, and cells with this are repainted and highlighted as well.

Data updates in non-event model

These processes are automatically launched when Row.Update()/Cell.Update() methods are invoked. Moreover, .Net Grid constantly monitors row state including their visibility, sorting position, grouping position and matching filtering conditions. Invocation of Row.Update() method initiates verification of all the above conditions for a single row among ordered rows in a grid. This process is much more efficient than working with unsorted data, especially during sorting. Invocation of Row.Update() in the event-driven model occurs regularly upon notification from the INotifyPropertyChanged interface. The Row.Update() method call is thread-safe, and therefore you don’t have to write your own thread synchronization logic. It is extremely convenient when you develop multi-threaded applications.

Therefore, when data is changed in the non-event model, you just have to invoke Row.Update()/Cell.Update() methods or Cell.Value setter, and .Net Grid will automatically perform all necessary operations with the row or with the cell.

 public void DataUpdating(Grid grid)
{
object[] data = new object[] {"value 1", 125, true, DockStyle.Fill};
Row row = grid.Rows.Add(data);

//The next calls will invalidate and highlight cells, and sort, filter and
//regroup the row

row[2].Value = false;
row[3].Value = DockStyle.Top;

//The last value in the data should equal to 'DockStyle.Top'.
Assert.AreEqual(data[3], DockStyle.Top);

//This call will also invalidate and highlight the cell, and sort, filter and
//regroup the row

data[1] = 125;
row[1].Update();

//The next call will just sort, filter and regroup the row
data[0] = "value 2";
row.Update();
}

Event-driven model

In the event-driven model it is sufficient to implement INotifyPropertyChanged interface to notify grid about data changes. This approach has very important advantages. The aforementioned interface is located in System.ComponentModel namespace and has only one public event - PropertyChanged. Because of that business logic can notify subscribers (GUI controls) through this interface and the .Net Grid itself performs data sortingfiltration and other operations. Moreover, a subscriber makes necessary actions for thread synchronization with the GUI thread. In other words, with good application architecture your assemblies with application logic will have no dependencies from Windows.Forms and Dapfor assemblies.

This is an implementation of the popular OOP design pattern that is known as Observer or Publisher / Subscriber.

This approach provides a considerable advantage over conventional programming models. Your applications may have multiple Graphic User Interfaces (multiple grids) that are subscribed to PropertyChanged event as event-listeners to the business object. A business object is an event generator or event publisher. When an object field changes in the setter of any property, the PropertyChanged
event is fired and all subscribers get guaranteed notification about it:

//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;
}

//Add a data object to the grid.
Product product = new Product();
Row row = grid.Rows.Add(product);

//The grid will automatically sort, filter, group and highlight corresponding row!
//NOTE, YOU DO NOT TOUCH THE GRID HERE!!!
//The product is your business logic and may be placed in any assembly that
//doesn't need to have references to Dapfor assemblies!

product.Price = 123;

//The value in the "Price" cell should equal to '123'.
Assert.AreEqual(row["Price"].Value, 123)

Performance

We would also like to emphasize performance advantages of the .Net Grid. In an unsorted grid all rows are systematically indexed, and when sorting is enabled, the search occurs at most ln(N) iterations – due to efficient algorithmsused in .Net Grid. It’s obvious that storing row state data consumes memory. Average memory consumption per row equals to 160 bytes, and that results in 16 MB per 100,000 data objects inserted into the grid, while the performance advantage is tremendous! The grid with 2,000 rows enables updating of more than 50,000 cells and sorting of more than 3,000 rows per second in realtime!

 

Back to .Net Grid Features