.Net Grid provides an extremely convenient mechanism of data highlighting. Highlighting is the process of changing background color of a cell for a specified time interval and gradual restoration of the initial color afterwards. Background color of a cell can be changed twice (at the beginning and at the end) or with a little periodicity (about 30 ms) enabling fading effect with gradual transition between the highlight color and the original background color of the cell.
In programming cell highlighting can be achieved by calling Cell.Highlight(Timespan, Color). When a programmer calls this method, the grid adds specific information about cell’s state into an internal container and launches timers when necessary. The second parameter is the color that may contain alpha-channel enabling mixing of the highlight color and the background color (transparency effect). It’s important to mention that the .Net Grid has a very easy to use API that saves programmer’s time. Highlighting management and initial parameters are accessible via Grid.Highlighting property.
Non-event model
C# | Copy |
---|---|
public void NonEventModelHighlighting(Grid grid) { //Initialize the grid grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("Name")); grid.Headers[0].Add(new Column("Color")); grid.Headers[0].Add(new Column("Price")); //Set highlighting parameters grid.Highlighting.Fading = true; grid.Highlighting.Interval = TimeSpan.FromSeconds(2); //Set semi-transparent color grid.Highlighting.Color = Color.FromArgb(128, Color.Red); //Populate the grid Row rowMercedes = grid.Rows.Add(new object[] { "Mercedes", Color.Black, 25000d }); Row rowBMW = grid.Rows.Add(new object[] { "BMW", Color.White, 35000d }); //Cut off the BMW's price rowBMW["Price"].Value = 24000d; //Highlight 'BMW' name with the green color for 3 seconds rowBMW["Name"].Highlight(TimeSpan.FromSeconds(3), Color.Green); } |
Event-driven model
In the event-driven model, highlighting is performed by receiving notifications via INotifyPropertyChanged interface. Highlighting values are taken from the Grid.Highlighting property. It means that data can be highlighted in such a way that the business logic won’t have dependencies from either System.Windows.Forms controls or Dapfor assemblies.
The same example in the event-driven model:
C# | Copy |
---|---|
//Some data object public class Car : INotifyPropertyChanged { private readonly string name; private readonly Color color; private double price; public Car(string name, Color color, double price) { this.name = name; this.color = color; this.price = price; } public string Name { get { return name; } } public Color Color { get { return color; } } public double Price { get { return price; } set { if (price != value) { price = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Price")); } } } } public event PropertyChangedEventHandler PropertyChanged; } public void EventDrivenModelHighlighting(Grid grid) { //Initialize the grid grid.Headers.Add(new Header()); grid.Headers[0].Add(new Column("Name")); grid.Headers[0].Add(new Column("Color")); grid.Headers[0].Add(new Column("Price")); //Set highlighting parameters grid.Highlighting.Fading = true; grid.Highlighting.Interval = TimeSpan.FromSeconds(2); //Set semi-transparent color grid.Highlighting.Color = Color.FromArgb(128, Color.Red); Car mercedes = new Car("Mercedes", Color.Black, 25000); Car bmw = new Car("BMW", Color.White, 35000); //Populate the grid grid.Rows.Add(mercedes); grid.Rows.Add(bmw); //Cut off the BMW's price //The .Net Grid will get a notification via INotifyPropertyChanged interface //and will highlight the 'Price' cell for 2 seconds with semi-transparent Red color bmw.Price = 24000d; } |
Performance
The .Net Grid systematically deletes useless information and launches timers only when it is really needed for specific interval. This results in considerable incrase of grid performance, especially when cells are highlighted only in visible area of the grid. We have implemented highlighting in .Net Grid in such a way, that it provides huge performance bonuses! Just imagine: the grid can highlight more than 50,000 cells per second with more than 5,000 rows!!!