Null Values Example for WPF

Nevron NOV Grid for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Grid examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Null Values Example for WPF Description

Demonstrates the grid support for null values. Note that the grid also supports editing of null values.


Null Values Example

C# Null Values Example Code for Nevron Grid for WPF
Language: C#

using Nevron.Nov;
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 - NNullValuesExample";

			// 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()
        {
            // create a memory data table that supports null values
            NMemoryDataTable table = new NMemoryDataTable();
            table.AddField(new NFieldInfo("Name", typeof(string), true));
            table.AddField(new NFieldInfo("Birthday", typeof(DateTime), true));
            table.AddField(new NFieldInfo("Country", typeof(ENCountry), true));
            table.AddField(new NFieldInfo("Email", typeof(string), true));

            Random rnd = new Random();
            for (int i = 0; i < NDummyDataSource.PersonInfos.Length; i++)
            {
                NDummyDataSource.NPersonInfo personInfo = NDummyDataSource.PersonInfos[i];

                bool nullName = (rnd.Next(8) == 1);
                bool nullBirthday = (rnd.Next(8) == 2);
                bool nullCountry = (rnd.Next(8) == 3);
                bool nullEmail = (rnd.Next(8) == 4);

                table.AddRow(
                    (nullName ? null : personInfo.Name),                  // name
                    (nullBirthday ? null : (object)personInfo.Birthday),  // birthday
                    (nullCountry ? null : (object)personInfo.Country),  // country
                    (nullEmail ? null : personInfo.Email));               // email
            }            

            m_TableView = new NTableGridView();
            m_TableView.Grid.DataSource = new NDataSource(table);
            m_TableView.Grid.AllowEdit = true;
            return m_TableView;
        }
        public NWidget CreateExampleControls()
        {
            return null;
        }
        public string GetExampleDescription()
        {
            return @"

Demonstrates the grid support for null values. Note that the grid also supports editing of null values.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Cells", "https://www.nevron.com/docs/openvision/grid-cells.html"), ("Grid Column Editors", "https://www.nevron.com/docs/openvision/grid-column-editors.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NTableGridView m_TableView; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Null Values Example for WPF Solution

VB.NET Null Values Example Code for Nevron Grid for WPF
Language: VB.NET

Imports Nevron.Nov
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 - NNullValuesExample"

		' 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
            ' create a memory data table that supports null values
            Dim table As NMemoryDataTable = New NMemoryDataTable()
            table.AddField(New NFieldInfo("Name", GetType(String), True))
            table.AddField(New NFieldInfo("Birthday", GetType(Date), True))
            table.AddField(New NFieldInfo("Country", GetType(ENCountry), True))
            table.AddField(New NFieldInfo("Email", GetType(String), True))

            Dim rnd As Random = New Random()
            For i As Integer = 0 To NDummyDataSource.PersonInfos.Length - 1
                Dim personInfo As NDummyDataSource.NPersonInfo = NDummyDataSource.PersonInfos(i)

                Dim nullName = rnd.Next(8) = 1
                Dim nullBirthday = rnd.Next(8) = 2
                Dim nullCountry = rnd.Next(8) = 3
                Dim nullEmail = rnd.Next(8) = 4

                table.AddRow(If(nullName, Nothing, personInfo.Name), If(nullBirthday, Nothing, CObj(personInfo.Birthday)), If(nullCountry, Nothing, CObj(personInfo.Country)), If(nullEmail, Nothing, personInfo.Email))                  ' name
                ' birthday
                ' country
                ' email
            Next

            m_TableView = New NTableGridView()
            m_TableView.Grid.DataSource = New NDataSource(table)
            m_TableView.Grid.AllowEdit = True
            Return m_TableView
        End Function
        Public Function CreateExampleControls() As NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return "

Demonstrates the grid support for null values. Note that the grid also supports editing of null values.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Grid Cells", "https://www.nevron.com/docs/openvision/grid-cells.html"), ("Grid Column Editors", "https://www.nevron.com/docs/openvision/grid-column-editors.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_TableView As NTableGridView #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Null Values Example for WPF Solution

Related Documentation Links