Demonstrates formula row values in combination with grouping rules.
In this example we have created two grouping rules, one that groups by the Company field and another one that groups by the Sales larger than 1000. Both conditions have been expressed with instances of the NFormulaRowValue.
Furthermore the example creates custom group row cells that display the "Sales greater than 1000" or "Sales less than or equal to 1000" for the second grouping rule rows.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Grid;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NFormulaGroupingExample";
// Create the NOV example and its controls
NWidget exampleContent = CreateExampleContent();
NWidget exampleControls = CreateExampleControls();
if (exampleControls != null)
{
exampleControls.PreferredWidth = 300;
}
// Place the example and its controls in a pair box
NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
pairBox.FillMode = ENStackFillMode.First;
pairBox.FitMode = ENStackFitMode.First;
pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);
// Host the example in the form
NNovWidgetHost host = new NNovWidgetHost(pairBox);
host.Dock = DockStyle.Fill;
Controls.Add(host);
}
#endregion
#region Example
public NWidget CreateExampleContent()
{
NTableGridView gridView = new NTableGridView();
NTableGrid grid = gridView.Grid;
// bind the grid to the data source
grid.DataSource = NDummyDataSource.CreateCompanySalesDataSource();
// create a grouping rule that groups by the company field value first
// note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
NColumn companyColumn = grid.Columns.GetColumnByFieldName("Company");
string fx1 = grid.CreateFormulaFieldName("Company");
NFormulaRowValue fxRowValue = new NFormulaRowValue(fx1);
NGroupingRule groupingRule1 = new NGroupingRule(companyColumn, fxRowValue, ENSortingDirection.Ascending);
grid.GroupingRules.Add(groupingRule1);
// create a grouping rule that groups by sales larger than 1000 next
// note that in order to indicate the grouping in the grouping panel, the rule must reference the respective column
string fx2 = grid.CreateFormulaFieldName("Sales") + ">1000";
NColumn salesColumn = grid.Columns.GetColumnByFieldName("Sales");
NGroupingRule groupingRule2 = NGroupingRule.FromFormula(salesColumn, fx2);
groupingRule2.CreateGroupRowCellsDelegate += delegate(NGroupingRuleCreateGroupRowCellsArgs arg)
{
bool groupValue = (bool)((NVariant)arg.GroupRow.GroupValue);
string text = groupValue? "Sales greater than 1000" : "Sales less than or equal to 1000";
return new NGroupRowCell[] { new NGroupRowCell(text) };
};
grid.GroupingRules.Add(groupingRule2);
// alter some view preferences
grid.AllowSortColumns = true;
grid.AlternatingRows = true;
grid.RowHeaders.Visible = true;
return gridView;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
Demonstrates formula row values in combination with grouping rules.
In this example we have created two grouping rules, one that groups by the Company field and another one that groups by the Sales larger than 1000.
Both conditions have been expressed with instances of the NFormulaRowValue.
Furthermore the example creates custom group row cells that display the ""Sales greater than 1000"" or ""Sales less than or equal to 1000"" for the second grouping rule rows.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Grid Grouping", "https://www.nevron.com/docs/openvision/grid-grouping.html"),
("Formula Basics", "https://www.nevron.com/docs/openvision/formula-basics.html"),
("Functions", "https://www.nevron.com/docs/openvision/formula-functions.html"),
("Grid Row Values", "https://www.nevron.com/docs/openvision/grid-row-values.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}