This example demonstrates how to create a simple combo box with text only items and how to add/remove items. You can use the buttons on the right to add/remove items from the combo box's Items collection.

| Language: C# |
using Nevron.Nov;
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 - NComboBoxItemsManipulationExample";
// 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
private NWidget CreateExampleContent()
{
return null;
}
private NWidget CreateExampleControls()
{
return null;
}
#endregion
#region Implementation
private NGroupBox CreateCommandsGroupBox()
{
NStackPanel commandsStack = new NStackPanel();
NButton addButton = new NButton("Add Item");
addButton.Click += OnAddButtonClick;
commandsStack.Add(addButton);
NButton removeSelectedButton = new NButton("Remove Selected");
removeSelectedButton.Click += OnRemoveSelectedButtonClick;
commandsStack.Add(removeSelectedButton);
NButton removeAllButton = new NButton("Remove All");
removeAllButton.Click += OnRemoveAllButtonClick;
commandsStack.Add(removeAllButton);
return new NGroupBox("Commands", commandsStack);
}
#endregion
#region Event Handlers
private void OnComboBoxSelectedIndexChanged(NValueChangeEventArgs args)
{
NComboBox comboBox = (NComboBox)args.TargetNode;
m_EventsLog.LogEvent("Selected Index: " + comboBox.SelectedIndex.ToString());
}
private void OnAddButtonClick(NEventArgs args)
{
m_ComboBox.Items.Add(new NComboBoxItem("Item " + m_ComboBox.Items.Count));
}
private void OnRemoveSelectedButtonClick(NEventArgs args)
{
if (m_ComboBox.SelectedIndex != -1)
{
m_ComboBox.Items.RemoveAt(m_ComboBox.SelectedIndex);
m_ComboBox.SelectedIndex = -1;
}
}
private void OnRemoveAllButtonClick(NEventArgs args)
{
m_ComboBox.Items.Clear();
}
#endregion
#region Fields
private NComboBox m_ComboBox;
private NExampleEventsLog m_EventsLog;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}