Demonstrates custom column formatting.
The custom column format is represented by the NCustomColumnFormat class. It exposes a set of delegates that you can hook to create your own widgets that represent the row values.
In this example we are using the NOV Chart for .NET to display Double[] values.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Data;
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;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NCustomColumnFormatsExample";
// 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()
{
NMemoryDataTable dataTable = new NMemoryDataTable(
new NFieldInfo("Company", typeof(String)),
new NFieldInfo("RegionSales", typeof(Double[])));
Random rnd = new Random();
for (int i = 0; i < 1000; i++)
{
Double[] arr = new Double[10];
for (int j = 0; j < 10; j++)
{
arr[j] = rnd.Next(100);
}
dataTable.AddRow(NDummyDataSource.RandomCompanyName(), arr);
}
// create a view and get its grid
NTableGridView view = new NTableGridView();
NTableGrid grid = view.Grid;
grid.AutoCreateColumn += delegate(NAutoCreateColumnEventArgs arg)
{
if (arg.DataColumn.FieldName == "RegionSales")
{
NCustomColumnFormat pieColumnFormat = new NCustomColumnFormat();
pieColumnFormat.FormatDefaultCellDelegate = delegate(NColumnCell cell)
{
NWidget widget = new NWidget();
widget.PreferredSize = new NSize(400, 300);
};
pieColumnFormat.CreateCellViewDelegate = delegate(NColumnCell cell, object value)
{
double[] values = (double[])value;
NChartView chartView = new NChartView();
chartView.PreferredSize = new NSize(300, 60);
NCartesianChart cartesianChart = new NCartesianChart();
NDockLayout.SetDockArea(cartesianChart, ENDockArea.Center);
chartView.Surface.Content = cartesianChart;
cartesianChart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
cartesianChart.Legend = null;
cartesianChart.Axes[ENCartesianAxis.PrimaryX].Visible = false;
NCartesianAxis yAxis = cartesianChart.Axes[ENCartesianAxis.PrimaryY];
NValueScaleLabelStyle labelStyle = new NValueScaleLabelStyle();
labelStyle.TextStyle.Font = new NFont("Arimo", 8);
((NLinearScale)yAxis.Scale).Labels.Style = labelStyle;
NBarSeries barSeries = new NBarSeries();
barSeries.DataLabelStyle = new NDataLabelStyle(false);
barSeries.InflateMargins = false;
cartesianChart.Series.Add(barSeries);
int count = values.Length;
for (int i = 0; i < count; i++)
{
barSeries.DataPoints.Add(new NBarDataPoint(values[i]));
}
return chartView;
};
arg.DataColumn.Format = pieColumnFormat;
}
};
grid.DataSource = new NDataSource(dataTable);
return view;
}
public NWidget CreateExampleControls()
{
return null;
}
public string GetExampleDescription()
{
return @"
Demonstrates custom column formatting.
The custom column format is represented by the NCustomColumnFormat class. It exposes a set of delegates that you can hook to create your own widgets that represent the row values.
In this example we are using the NOV Chart for .NET to display Double[] values.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"),
("Grid Data Columns", "https://www.nevron.com/docs/openvision/grid-data-columns.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.Chart
Imports Nevron.Nov.Data
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Grid
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NCustomColumnFormatsExample"
' 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)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
Dim dataTable As NMemoryDataTable = New NMemoryDataTable(New NFieldInfo("Company", GetType(String)), New NFieldInfo("RegionSales", GetType(Double())))
Dim rnd As Random = New Random()
For i = 0 To 999
Dim arr = New Double(9) {}
For j = 0 To 9
arr(j) = rnd.Next(100)
Next
dataTable.AddRow(NDummyDataSource.RandomCompanyName(), arr)
Next
' create a view and get its grid
Dim view As NTableGridView = New NTableGridView()
Dim grid = view.Grid
grid.AutoCreateColumn += Sub(arg As NAutoCreateColumnEventArgs)
If Equals(arg.DataColumn.FieldName, "RegionSales") Then
Dim pieColumnFormat As NCustomColumnFormat = New NCustomColumnFormat()
pieColumnFormat.FormatDefaultCellDelegate = Sub(cell As NColumnCell)
Dim widget As NWidget = New NWidget()
widget.PreferredSize = New NSize(400, 300)
End Sub
pieColumnFormat.CreateCellViewDelegate = Function(cell As NColumnCell, value)
Dim values = CType(value, Double())
Dim chartView As NChartView = New NChartView()
chartView.PreferredSize = New NSize(300, 60)
Dim cartesianChart As NCartesianChart = New NCartesianChart()
NDockLayout.SetDockArea(cartesianChart, ENDockArea.Center)
chartView.Surface.Content = cartesianChart
cartesianChart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
cartesianChart.Legend = Nothing
cartesianChart.Axes(ENCartesianAxis.PrimaryX).Visible = False
Dim yAxis = cartesianChart.Axes(ENCartesianAxis.PrimaryY)
Dim labelStyle As NValueScaleLabelStyle = New NValueScaleLabelStyle()
labelStyle.TextStyle.Font = New NFont("Arimo", 8)
CType(yAxis.Scale, NLinearScale).Labels.Style = labelStyle
Dim barSeries As NBarSeries = New NBarSeries()
barSeries.DataLabelStyle = New NDataLabelStyle(False)
barSeries.InflateMargins = False
cartesianChart.Series.Add(barSeries)
Dim count = values.Length
For i = 0 To count - 1
barSeries.DataPoints.Add(New NBarDataPoint(values(i)))
Next
Return chartView
End Function
arg.DataColumn.Format = pieColumnFormat
End If
End Sub
grid.DataSource = New NDataSource(dataTable)
Return view
End Function
Public Function CreateExampleControls() As NWidget
Return Nothing
End Function
Public Function GetExampleDescription() As String
Return "
Demonstrates custom column formatting.
The custom column format is represented by the NCustomColumnFormat class. It exposes a set of delegates that you can hook to create your own widgets that represent the row values.
In this example we are using the NOV Chart for .NET to display Double[] values.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Grid Column Formats", "https://www.nevron.com/docs/openvision/grid-column-formats.html"), ("Grid Data Columns", "https://www.nevron.com/docs/openvision/grid-data-columns.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