Items Manipulation Example for WPF

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

Items Manipulation Example for WPF Description

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.


Combo Box Items Manipulation Example

C# Items Manipulation Example Code for Nevron UserInterface for WPF
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
	}
}

Download a fully functional C# (.cs) Items Manipulation Example for WPF Solution

VB.NET Items Manipulation Example Code for Nevron UserInterface for WPF
Language: VB.NET

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

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

	Private Function CreateExampleControls() As NWidget
		Return Nothing
	End Function

	Private Function CreateExampleContent() As NWidget
		Return Nothing
	End Function

#End Region

#Region "Implementation"

        Private Function CreateCommandsGroupBox() As NGroupBox
            Dim commandsStack As NStackPanel = New NStackPanel()

            Dim addButton As NButton = New NButton("Add Item")
            addButton.Click += AddressOf OnAddButtonClick
            commandsStack.Add(addButton)

            Dim removeSelectedButton As NButton = New NButton("Remove Selected")
            removeSelectedButton.Click += AddressOf OnRemoveSelectedButtonClick
            commandsStack.Add(removeSelectedButton)

            Dim removeAllButton As NButton = New NButton("Remove All")
            removeAllButton.Click += AddressOf OnRemoveAllButtonClick
            commandsStack.Add(removeAllButton)

            Return New NGroupBox("Commands", commandsStack)
        End Function

#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
        Private Sub OnAddButtonClick(args As NEventArgs)
            m_ComboBox.Items.Add(New NComboBoxItem("Item " & m_ComboBox.Items.Count.ToString()))
        End Sub
        Private Sub OnRemoveSelectedButtonClick(args As NEventArgs)
            If m_ComboBox.SelectedIndex <> -1 Then
                m_ComboBox.Items.RemoveAt(m_ComboBox.SelectedIndex)
                m_ComboBox.SelectedIndex = -1
            End If
        End Sub
        Private Sub OnRemoveAllButtonClick(args As NEventArgs)
            m_ComboBox.Items.Clear()
        End Sub

#End Region

#Region "Fields"

        Private m_ComboBox As NComboBox
        Private m_EventsLog As NExampleEventsLog

#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) Items Manipulation Example for WPF Solution