Tree Grid View (List Tree View) Example for WinForms

Nevron NOV Grid for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms 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.

Tree Grid View (List Tree View) Example for WinForms Description

Demonstrates the NTreeGridView and NTreeGrid

The NTreeGridView represents a grid that displays hierarchical data from the data source.

The hierarchy is encoded in the data source with the help of two service fields:
Id - uniquely identifies the records in the data source.
ParentId - identifies the parent record of a specific record by Id.

Usually the service fields of the data source are not displayed by the Tree Grid as is the case in this example.


Tree Grid View Example

C# Tree Grid View (List Tree View) Example Code for Nevron Grid for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Data;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Grid;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
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 - NTreeGridViewExample";

			// 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 hieararchical data table that represents a simple organization.
            NMemoryDataTable dataTable = new NMemoryDataTable(new NFieldInfo[]{
                new NFieldInfo("Id", typeof(Int32)),
                new NFieldInfo("ParentId", typeof(Int32)),
                new NFieldInfo("Name", typeof(String)),
                new NFieldInfo("Job Title", typeof(ENJobTitle)),
                new NFieldInfo("Company", typeof(string)),
            });

            int i = 0;

            // company 1
            dataTable.AddRow(0, -1, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.President, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(1, 0, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.VicePresident, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(2, 1, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesManager, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(3, 2, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(4, 2, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(5, 1, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.LeadDevelop, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(6, 5, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames[0]);
            dataTable.AddRow(7, 5, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames[0]);

            // company 2
            dataTable.AddRow(8, -1, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.President, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(9, 8, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.VicePresident, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(10, 9, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesManager, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(11, 10, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(12, 10, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(13, 10, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(14, 9, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.LeadDevelop, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(15, 14, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(16, 14, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames[1]);
            dataTable.AddRow(17, 14, NDummyDataSource.PersonInfos[i++].Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames[1]);

            // create a tree grid view
            // records are identified by the Id field.
            // the parent of each record is specified by the ParentId field.
            m_TreeGridView = new NTreeGridView();
            m_TreeGridView.Grid.IdFieldName = "Id";
            m_TreeGridView.Grid.ParentIdFieldName = "ParentId";
            m_TreeGridView.Grid.DataSource = new NDataSource(dataTable);

            return m_TreeGridView;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();

            NList editors = NDesigner.GetDesigner(m_TreeGridView.Grid).CreateMemberEditors(
                m_TreeGridView.Grid,
                NGrid.FrozenRowsProperty,
                NGrid.IntegralVScrollProperty);

            for (int i = 0; i < editors.Count; i++)
            {
                stack.Add(editors[i]);
            }

            return stack;
        }
        public string GetExampleDescription()
        {
            return @"

Demonstrates the NTreeGridView and NTreeGrid

The NTreeGridView represents a grid that displays hierarchical data from the data source.

The hierarchy is encoded in the data source with the help of two service fields:
Id - uniquely identifies the records in the data source.
ParentId - identifies the parent record of a specific record by Id.

Usually the service fields of the data source are not displayed by the Tree Grid as is the case in this example.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Self Referencing", "https://www.nevron.com/docs/openvision/grid-self-referencing.html"), ("Grid Data Processing Overview", "https://www.nevron.com/docs/openvision/grid-data-processing-overview.html"), ("Grid Rows", "https://www.nevron.com/docs/openvision/grid-rows.html"), ("Grid Data Binding and Column Generation", "https://www.nevron.com/docs/openvision/grid-data-binding-and-column-generation.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NTreeGridView m_TreeGridView; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Tree Grid View (List Tree View) Example for WinForms Solution

VB.NET Tree Grid View (List Tree View) Example Code for Nevron Grid for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Data
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Grid
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System

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 - NTreeGridViewExample"

        ' 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
            ' create a hieararchical data table that represents a simple organization.
            Dim dataTable As NMemoryDataTable = New NMemoryDataTable(New NFieldInfo() {New NFieldInfo("Id", GetType(Integer)), New NFieldInfo("ParentId", GetType(Integer)), New NFieldInfo("Name", GetType(String)), New NFieldInfo("Job Title", GetType(ENJobTitle)), New NFieldInfo("Company", GetType(String))})

            Dim i = 0

            ' company 1
            dataTable.AddRow(0, -1, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.President, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(1, 0, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.VicePresident, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(2, 1, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesManager, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(3, 2, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(4, 2, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(5, 1, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.LeadDevelop, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(6, 5, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames(0))
            dataTable.AddRow(7, 5, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames(0))

            ' company 2
            dataTable.AddRow(8, -1, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.President, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(9, 8, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.VicePresident, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(10, 9, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesManager, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(11, 10, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(12, 10, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(13, 10, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SalesRepresentative, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(14, 9, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.LeadDevelop, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(15, 14, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(16, 14, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames(1))
            dataTable.AddRow(17, 14, NDummyDataSource.PersonInfos(CInt(Math.Min(System.Threading.Interlocked.Increment(i), i - 1))).Name, ENJobTitle.SeniorDeveloper, NDummyDataSource.CompanyNames(1))

            ' create a tree grid view
            ' records are identified by the Id field.
            ' the parent of each record is specified by the ParentId field.
            m_TreeGridView = New NTreeGridView()
            m_TreeGridView.Grid.IdFieldName = "Id"
            m_TreeGridView.Grid.ParentIdFieldName = "ParentId"
            m_TreeGridView.Grid.DataSource = New NDataSource(dataTable)

            Return m_TreeGridView
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim editors = NDesigner.GetDesigner(m_TreeGridView.Grid).CreateMemberEditors(m_TreeGridView.Grid, NGrid.FrozenRowsProperty, NGrid.IntegralVScrollProperty)

            For i = 0 To editors.Count - 1
                stack.Add(editors(i))
            Next

            Return stack
        End Function
        Public Function GetExampleDescription() As String
            Return "

Demonstrates the NTreeGridView and NTreeGrid

The NTreeGridView represents a grid that displays hierarchical data from the data source.

The hierarchy is encoded in the data source with the help of two service fields:
Id - uniquely identifies the records in the data source.
ParentId - identifies the parent record of a specific record by Id.

Usually the service fields of the data source are not displayed by the Tree Grid as is the case in this example.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Grid Self Referencing", "https://www.nevron.com/docs/openvision/grid-self-referencing.html"), ("Grid Data Processing Overview", "https://www.nevron.com/docs/openvision/grid-data-processing-overview.html"), ("Grid Rows", "https://www.nevron.com/docs/openvision/grid-rows.html"), ("Grid Data Binding and Column Generation", "https://www.nevron.com/docs/openvision/grid-data-binding-and-column-generation.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_TreeGridView As NTreeGridView #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) Tree Grid View (List Tree View) Example for WinForms Solution