This example demonstrates how to create a simple combo box with text only items. You can use the controls on the right to modify various properties of the combo box.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NComboBoxFirstLookExample";
// 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 the combo box
m_ComboBox = new NComboBox();
m_ComboBox.HorizontalPlacement = ENHorizontalPlacement.Left;
m_ComboBox.VerticalPlacement = ENVerticalPlacement.Top;
m_ComboBox.DropDownStyle = ENComboBoxStyle.DropDownList;
// add a few items
for (int i = 0; i < 10; i++)
{
m_ComboBox.Items.Add(new NComboBoxItem("Item " + i.ToString()));
}
// select the first item
m_ComboBox.SelectedIndex = 0;
// hook combo box selection events
m_ComboBox.SelectedIndexChanged += OnComboBoxSelectedIndexChanged;
return m_ComboBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
stack.FillMode = ENStackFillMode.Last;
stack.FitMode = ENStackFitMode.Last;
NStackPanel propertiesStack = new NStackPanel();
NList editors = NDesigner.GetDesigner(m_ComboBox).CreateMemberEditors(
m_ComboBox,
NComboBox.EnabledProperty,
NComboBox.HorizontalPlacementProperty,
NComboBox.VerticalPlacementProperty,
NComboBox.DropDownButtonPositionProperty,
NComboBox.SelectedIndexProperty,
NComboBox.DropDownStyleProperty,
NComboBox.WheelNavigationModeProperty);
for (int i = 0; i < editors.Count; i++)
{
propertiesStack.Add(editors[i]);
}
stack.Add(new NGroupBox("Properties", new NUniSizeBoxGroup(propertiesStack)));
// create the events list box
m_EventsLog = new NExampleEventsLog();
stack.Add(m_EventsLog);
return stack;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create a simple combo box with text only items. You can use the controls
on the right to modify various properties of the combo box.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Combo Box", "https://www.nevron.com/docs/openvision/ui-combo-box.html"),
("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnComboBoxSelectedIndexChanged(NValueChangeEventArgs args)
{
NComboBox comboBox = (NComboBox)args.TargetNode;
m_EventsLog.LogEvent("Selected Index: " + comboBox.SelectedIndex.ToString());
}
#endregion
#region Fields
private NExampleEventsLog m_EventsLog;
private NComboBox m_ComboBox;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | Language: VB.NET |
Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
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 - NComboBoxFirstLookExample"
' 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 the combo box
m_ComboBox = New NComboBox()
m_ComboBox.HorizontalPlacement = ENHorizontalPlacement.Left
m_ComboBox.VerticalPlacement = ENVerticalPlacement.Top
m_ComboBox.DropDownStyle = ENComboBoxStyle.DropDownList
' add a few items
For i = 0 To 9
m_ComboBox.Items.Add(New NComboBoxItem("Item " & i.ToString()))
Next
' select the first item
m_ComboBox.SelectedIndex = 0
' hook combo box selection events
Me.m_ComboBox.SelectedIndexChanged += AddressOf OnComboBoxSelectedIndexChanged
Return m_ComboBox
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
stack.FillMode = ENStackFillMode.Last
stack.FitMode = ENStackFitMode.Last
Dim propertiesStack As NStackPanel = New NStackPanel()
Dim editors = NDesigner.GetDesigner(m_ComboBox).CreateMemberEditors(m_ComboBox, NInputElement.EnabledProperty, NWidget.HorizontalPlacementProperty, NWidget.VerticalPlacementProperty, NDropDownEdit.DropDownButtonPositionProperty, NComboBox.SelectedIndexProperty, NComboBox.DropDownStyleProperty, NComboBox.WheelNavigationModeProperty)
For i = 0 To editors.Count - 1
propertiesStack.Add(editors(i))
Next
stack.Add(New NGroupBox("Properties", New NUniSizeBoxGroup(propertiesStack)))
' create the events list box
m_EventsLog = New NExampleEventsLog()
stack.Add(m_EventsLog)
Return stack
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create a simple combo box with text only items. You can use the controls
on the right to modify various properties of the combo box.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Combo Box", "https://www.nevron.com/docs/openvision/ui-combo-box.html"), ("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnComboBoxSelectedIndexChanged(args As NValueChangeEventArgs)
Dim comboBox = CType(args.TargetNode, NComboBox)
m_EventsLog.LogEvent("Selected Index: " & comboBox.SelectedIndex.ToString())
End Sub
#End Region
#Region "Fields"
Private m_EventsLog As NExampleEventsLog
Private m_ComboBox As NComboBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class