AddRange Method

ComboBox.ObjectCollection.AddRange Method (Object[])


Adds an array of items to the list of items for a ComboBox.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public void AddRange(
	object[] items


Type: System.Object[]

An array of objects to add to the list.

Exception Condition

An item in the items parameter was null.

If the Sorted property of the ComboBox is set to true, the items are inserted into the list alphabetically. Otherwise, the items are inserted in the order they occur within the array. This method is typically passed an array of String objects, but an array of any type of object can be passed to this method. When an object is added to the collection, the method calls the object's ToString method to obtain the string to display in the list. When using this method to add items to the collection, you do not need to call the BeginUpdate and EndUpdate methods to optimize performance.

The following code example demonstrates how to initialize a ComboBox control by setting the text property and using the AddRange method to populate the ComboBox. It also demonstrates handling the DropDown event. To run the example, paste the following code in a form and call the InitializeComboBox method from the form's constructor or Load method.

Snippet section 2 of code snippet {"project_id":"3fedad16-eaf1-41a6-8f96-0c1949c68f32","entity_id":"38ab5e3e-4e74-47ea-878b-31f3f46ca9ad","entity_type":"CodeSnippet","locale":"en-US"} in source file ({"filename":"/CS/form1.cs","blob_type":"Source","blob_id":"-002fcs-002fform1-002ecs","blob_revision":2}) overlaps with other snippet sections. Ensure the tags are placed correctly.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft