Column Width 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.

Column Width Example for WinForms Description

Demonstrates the column properties that affect the column width.

Select a column from the Select Column combo box and explore the properties that control the selected column width.


Columns Width Example

C# Column Width 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 - NColumnsWidthExample";

			// 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()
        {
            m_TableView = new NTableGridView();
            m_TableView.Grid.DataSource = NDummyDataSource.CreatePersonsDataSource();
            return m_TableView;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            
            // create the columns combo box
            stack.Add(new NLabel("Select Column:"));
            
            m_ColumnsComboBox = new NComboBox();
            stack.Add(m_ColumnsComboBox);

            for (int i = 0; i < m_TableView.Grid.Columns.Count; i++)
            {
                NColumn column = m_TableView.Grid.Columns[i];

                NComboBoxItem item = new NComboBoxItem(column.Title);
                item.Tag = column;
                m_ColumnsComboBox.Items.Add(item);
            }

            m_ColumnsComboBox.SelectedIndexChanged += OnColumnsComboBoxSelectedIndexChanged;

            // create the columns 
            m_ColumnPropertiesHolder = new NContentHolder();
            stack.Add(new NGroupBox("Selected Column Properties", m_ColumnPropertiesHolder));

            return stack;
        }

        public string GetExampleDescription()
        {
            return @"

Demonstrates the column properties that affect the column width.

Select a column from the Select Column combo box and explore the properties that control the selected column width.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Column Width", "https://www.nevron.com/docs/openvision/grid-column-width.html"), ("Grid Columns", "https://www.nevron.com/docs/openvision/grid-columns.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnColumnsComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { NComboBoxItem item = m_ColumnsComboBox.SelectedItem; if (item == null) { m_ColumnPropertiesHolder.Content = null; } else { NColumn column = (NColumn)item.Tag; NStackPanel columnPropertiesStack = new NStackPanel(); m_ColumnPropertiesHolder.Content = new NUniSizeBoxGroup(columnPropertiesStack); NDesigner designer = NDesigner.GetDesigner(column); NList editors = designer.CreateMemberEditors( column, NColumn.WidthModeProperty, NColumn.FixedWidthProperty, NColumn.WidthPercentProperty ); for (int i = 0; i < editors.Count; i++) { columnPropertiesStack.Add(editors[i]); } } } #endregion #region Fields NTableGridView m_TableView; NComboBox m_ColumnsComboBox; NContentHolder m_ColumnPropertiesHolder; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Column Width Example for WinForms Solution

VB.NET Column Width Example Code for Nevron Grid for WinForms
Language: VB.NET

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

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

        ' 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
            m_TableView = New NTableGridView()
            m_TableView.Grid.DataSource = NDummyDataSource.CreatePersonsDataSource()
            Return m_TableView
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            ' create the columns combo box
            stack.Add(New NLabel("Select Column:"))

            m_ColumnsComboBox = New NComboBox()
            stack.Add(m_ColumnsComboBox)

            For i = 0 To m_TableView.Grid.Columns.Count - 1
                Dim column = m_TableView.Grid.Columns(i)

                Dim item As NComboBoxItem = New NComboBoxItem(column.Title)
                item.Tag = column
                m_ColumnsComboBox.Items.Add(item)
            Next

            Me.m_ColumnsComboBox.SelectedIndexChanged += AddressOf OnColumnsComboBoxSelectedIndexChanged

            ' create the columns 
            m_ColumnPropertiesHolder = New NContentHolder()
            stack.Add(New NGroupBox("Selected Column Properties", m_ColumnPropertiesHolder))

            Return stack
        End Function

        Public Function GetExampleDescription() As String
            Return "

Demonstrates the column properties that affect the column width.

Select a column from the Select Column combo box and explore the properties that control the selected column width.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Grid Column Width", "https://www.nevron.com/docs/openvision/grid-column-width.html"), ("Grid Columns", "https://www.nevron.com/docs/openvision/grid-columns.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnColumnsComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) Dim item = m_ColumnsComboBox.SelectedItem If item Is Nothing Then m_ColumnPropertiesHolder.Content = Nothing Else Dim column As NColumn = item.Tag Dim columnPropertiesStack As NStackPanel = New NStackPanel() m_ColumnPropertiesHolder.Content = New NUniSizeBoxGroup(columnPropertiesStack) Dim designer = NDesigner.GetDesigner(column) Dim editors = designer.CreateMemberEditors(column, NColumn.WidthModeProperty, NColumn.FixedWidthProperty, NColumn.WidthPercentProperty) For i = 0 To editors.Count - 1 columnPropertiesStack.Add(editors(i)) Next End If End Sub #End Region #Region "Fields" Private m_TableView As NTableGridView Private m_ColumnsComboBox As NComboBox Private m_ColumnPropertiesHolder As NContentHolder #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) Column Width Example for WinForms Solution

Related Documentation Links