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
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Grid
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NFormulaGroupingExample"
' Create the NOV example and its controls
Dim exampleContent As NWidget = CreateExampleContent()
Dim exampleControls As NWidget = CreateExampleControls()
If Not exampleControls Is Nothing Then
exampleControls.PreferredWidth = 300
End If
' Place the example and its controls in a pair box
Dim pairBox As NPairBox = 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
Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
Dim gridView As NTableGridView = New NTableGridView()
Dim 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
Dim companyColumn As NColumn = grid.Columns.GetColumnByFieldName("Company")
Dim fx1 = grid.CreateFormulaFieldName("Company")
Dim fxRowValue As NFormulaRowValue = New NFormulaRowValue(fx1)
Dim groupingRule1 As NGroupingRule = 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
Dim fx2 = grid.CreateFormulaFieldName("Sales") & ">1000"
Dim salesColumn As NColumn = grid.Columns.GetColumnByFieldName("Sales")
Dim groupingRule2 = NGroupingRule.FromFormula(salesColumn, fx2)
groupingRule2.CreateGroupRowCellsDelegate += Function(arg As NGroupingRuleCreateGroupRowCellsArgs)
Dim groupValue = CBool(CType(arg.GroupRow.GroupValue, NVariant))
Dim text = If(groupValue, "Sales greater than 1000", "Sales less than or equal to 1000")
Return New NGroupRowCell() {New NGroupRowCell(text)}
End Function
grid.GroupingRules.Add(groupingRule2)
' alter some view preferences
grid.AllowSortColumns = True
grid.AlternatingRows = True
grid.RowHeaders.Visible = True
Return gridView
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
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.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("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")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class