Tree Grid View (List Tree View) Example for Blazor

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

Tree Grid View (List Tree View) Example for Blazor 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 Blazor
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 Blazor Solution