CyDAS General Controls: Class MultiSelectCombobox

The class MultiSelectCombobox combines the multi-select feature of a list control with the look and feel of a combox.

It was created by combining a textbox, a button, and a listbox control. The textbox is used for displaying the selected items of the listbox control, separated by a user defined separator character. The listbox is opened by clicking on the button.

Properties and methods are mainly passed through to the listbox control. Only a few properties are specific or specially adjusted for the Multi-Select-Combobox and shown in bold print below.

Overview

MultiSelectCombobox
New() 
BackColor: Color
ColumnWidth: Integer
DataSource: Object
DisplayMember: String
DefaultSize: System.Drawing.Size {readonly}
DrawMode: System.Windows.Forms.DrawMode
DropDownWidth: Integer
Font: Font
ForeColor: Color
HorizontalExtent: Integer
HorizontalScrollbar: Boolean
IntegralHeight: Boolean
ItemHeight: Integer
Items: System.Windows.Forms.ListBox.ObjectCollection
ItemTextSeparator: Char
MaxDropDownItems: Integer
MultiColumn: Boolean
ScrollAlwaysVisible: Boolean
SelectedIndex: Integer
SelectedIndices: System.Windows.Forms.ListBox.SelectedIndexCollection {readonly}
SelectedItem: Object
SelectedItems: System.Windows.Forms.ListBox.SelectedObjectCollection {readonly}
SelectionMode: SelectionMode
Sorted: Boolean
Text: String
UseTabStops: Boolean
ValueMember: String
BeginUpdate(): Void
ClearSelected(): Void
EndUpdate(): Void
FindStringExact(ByVal s: String): Integer
FindStringExact(ByVal s: String, ByVal startIndex: Integer): Integer
FindString(ByVal s: String): Integer
FindStringExact(ByVal s: String, ByVal startIndex: Integer): Integer
GetItemHeight(ByVal index: Integer): Integer
GetItemRectangle(ByVal index: Integer): System.Drawing.Rectangle
GetSelected(ByVal index: Integer): Boolean
IndexFromPoint(ByVal x: Integer, ByVal y: Integer): Integer
IndexFromPoint(ByVal p: System.Drawing.Point): Integer
SetSelected(ByVal index: Integer, ByVal value: Boolean): Void
SelectedIndexChanged(ByVal sender: Object, ByVal e: System.EventArgs): Event
SelectedValueChanged(ByVal sender: Object, ByVal e: System.EventArgs): Event

Programming Language

  • Microsoft Visual Basic .Net.

Availability

Constructors

Public Sub New()

Instantiates a new MultiSelectCombobox object. There are no parameters for this function. The constructor call and its coding will normally happen automatically within the windows form designer.

Interfaces

There are no interfaces implemented.

Enumerations

The class does not provide enumerations.

Properties

BackColor As Color

Gets or sets the back color of the textbox and listbox portions of the control.

Property Value

  • the back color of the textbox and listbox portions of the control.

Remarks

ColumnWidth As Integer

The ColumnWidth property is passed through to ListBox.ColumnWidth.

DataSource As Object

The DataSource property is passed through to ListBox.DataSource.

DefaultSize As System.Drawing.Size

Returns the default size (= New Size(128;20)).

Overwrites Control.DefaultSize.

DisplayMember As String

The DisplayMember property is passed through to ListBox.DisplayMember.

DrawMode As System.Windows.Forms.DrawMode

The DrawMode property is passed through to ListBox.DrawMode.

DropDownWidth As Integer

The DropDownWidth property gets or sets the width of the listbox portion of the Multi-Select-Combobox. The list part may be wider or smaller than the textbox and button part of the control.

Property Value

  • the width of the listbox portion of the Multi-Select-Combobox.

Parameters

  • ByVal Value As Integer: the new value for the width.

Exceptions

Remarks

  • If no width is given, the list box width is set to the default width of the whole control.

Font as Font

Gets or sets the font of the textbox and listbox portions of the control.

Property Value

  • the font of the textbox and listbox portions of the control.

Remarks

  • the font of the "open" button remains unchanged.

ForeColor As Color

Gets or sets the foreground color of the textbox, listbox, and button portions of the control.

Property Value

  • the foreground color of the control.

HorizontalExtent As Integer

The HorizontalExtent property is passed through to ListBox.HorizontalExtent.

HorizontalScrollbar As Boolean

The HorizontalScrollbar property is passed through to ListBox.HorizontalScrollbar.

IntegralHeight As Boolean

The IntegralHeight property is passed through to ListBox.IntegralHeight.

ItemHeight As Integer

The ItemHeight property is passed through to ListBox.ItemHeight.

Items As System.Windows.Forms.ListBox.ObjectCollection

The Items property is passed through to ListBox.Items.

ItemTextSeparator As Char

The ItemTextSeparator is used to separate between the selected items in the textbox portion of the control.

Property Value

  • the character used for separating the selected items in the textbox portion of the control.

Parameters

  • Value As Char: the new value for the separator.

Remarks

  • Default value is a pipe sign ("|"). It is recommended to use a character which likely does not occur in the items.

MaxDropDownItems As Integer

The MaxDropDownItems property resembles Combobox.MaxDropDownItems: it gets or sets the maximum number of items to be displayed in the listbox portion.
Since the control actually does not contain a combobox, this property had to be implemented in the btnOpen_Click event handler.

Property Value

  • The maximum number of items to be shown in the drop-down portion.

Parameters

  • Value as Integer: The new value for the maximum number of items.

Remarks

  • Default value is 8.

MultiColumn As Boolean

The MultiColumn property is passed through to ListBox.MultiColumn.

ScrollAlwaysVisible As Boolean

The ScrollAlwaysVisible property is passed through to ListBox.ScrollAlwaysVisible.

SelectedIndex As Integer

The SelectedIndex property is passed through to ListBox.SelectedIndex.

ReadOnly SelectedIndices As System.Windows.Forms.ListBox.SelectedIndexCollection

The SelectedIndices property is passed through to ListBox.SelectedIndices.

SelectedItem As Object

The SelectedItem property is passed through to ListBox.SelectedItem.

ReadOnly SelectedItems As System.Windows.Forms.ListBox.SelectedObjectCollection

The SelectedItems property is passed through to ListBox.SelectedItems.

SelectionMode As SelectionMode

The SelectionMode property is passed through to ListBox.SelectionMode.

Sorted As Boolean

The Sorted property is passed through to ListBox.Sorted.

Text As String

Gets or sets the text shown in the textbox portion of the control.

Property Value

  • the text shown in the textbox portion of the control.

Parameters

  • Value as String: the new text to be displayed.

Remarks

  • The text property is also changed by selecting or deselecting items from the listbox portion of the control.

UseTabStops As Boolean

The UseTabStops property is passed through to ListBox.UseTabStops.

ValueMember As String

The ValueMember property is passed through to ListBox.ValueMember.

Methods

Function BeginUpdate() As Void

The BeginUpdate() function is passed through to ListBox.BeginUpdate().

Function ClearSelected() As Void

The ClearSelected() function is passed through to ListBox.ClearSelected().

Function EndUpdate() As Void

The EndUpdate() function is passed through to ListBox.EndUpdate().

Function FindStringExact(ByVal String) As Integer

The FindStringExact(ByVal s As String) function is passed through to ListBox.FindStringExact(String).

Function FindStringExact(ByVal String, ByVal Integer) As Integer

The FindStringExact(ByVal s As String, ByVal startIndex As Integer) function is passed through to ListBox.FindStringExact(ByVal s As String, ByVal startIndex As Integer).

Function FindString(ByVal String) As Integer

The FindString(ByVal s As String) function is passed through to ListBox.FindString(String).

Function FindString(ByVal String, ByVal Integer) As Integer

The FindString(ByVal s As String, ByVal startIndex As Integer) function is passed through to ListBox.FindString(String, Integer).

Function GetItemHeight(ByVal Integer) As Integer

The GetItemHeight() function is passed through to ListBox.GetItemHeight().

Function GetItemRectangle(ByVal Integer) As System.Drawing.Rectangle

The GetItemRectangle() function is passed through to ListBox.GetItemRectangle().

Function GetSelected(ByVal Integer) As Boolean

The GetSelected() function is passed through to ListBox.GetSelected().

Function IndexFromPoint(ByVal Integer, ByVal Integer) As Integer

The IndexFromPoint(Integer, Integer) function is passed through to ListBox.IndexFromPoint(Integer, Integer).

Function IndexFromPoint(ByVal p As System.Drawing.Point) As Integer

The IndexFromPoint(Point) function is passed through to ListBox.IndexFromPoint(Point).

Function SetSelected(ByVal index As Integer, ByVal value As Boolean) As Void

The SetSelected() function is passed through to ListBox.SetSelected().

Events

SelectedIndexChanged(ByVal sender: Object, ByVal e: System.EventArgs)

Occurs when the SelectedIndex property has changed, after updating the text in the textbox portion.

Sender is set to this instance of Multi-Select-Combobox Control, while the event arguments are taken from the internal ListBox.SelectedIndexChanged event.

SelectedValueChanged(ByVal sender: Object, ByVal e: System.EventArgs)

Occurs when the ValueMember property has changed, after updating the text in the textbox portion.

Sender is set to this instance of Multi-Select-Combobox Control, while the event arguments are taken from the internal ListBox.SelectedValueChanged event.

Interaction with other classes

Resources used by MultiSelectCombobox

MultiSelectCombobox inherits from System.Windows.Forms.UserControl.

It imports both System.Windows.Forms and System.Windows.Forms.ListBox.