Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions xml/System.Windows.Forms/ListBox+ObjectCollection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: <paramref name="owner" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName=".ctor">
Expand Down Expand Up @@ -138,6 +139,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: Either <paramref name="owner" /> or <paramref name="value" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName=".ctor">
Expand Down Expand Up @@ -171,6 +173,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: Either <paramref name="owner" /> or <paramref name="value" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="Add">
Expand Down Expand Up @@ -207,9 +210,7 @@
## Remarks
If the <xref:System.Windows.Forms.ListBox.Sorted%2A> property of the <xref:System.Windows.Forms.ListBox> is set to `true`, the item is inserted into the list alphabetically. Otherwise, the item is inserted at the end of the list. To insert an item into the list box at a specific position, use the <xref:System.Windows.Forms.ListBox.ObjectCollection.Insert%2A> method. To add a set of items to the list box in a single operation, use the <xref:System.Windows.Forms.ListBox.ObjectCollection.AddRange%2A> method. If you want to use the <xref:System.Windows.Forms.ListBox.ObjectCollection.Add%2A> method to add a large number of items to the list, use the <xref:System.Windows.Forms.ListBox.BeginUpdate%2A> and <xref:System.Windows.Forms.ListBox.EndUpdate%2A> methods to prevent the <xref:System.Windows.Forms.ListBox> from repainting each time an item is added to the list until all items are added to the list. When adding items to a <xref:System.Windows.Forms.ListBox>, it is more efficient to sort the items first and then add new items.

When an object is added to the collection, the <xref:System.Windows.Forms.ListBox> first checks to see if the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property of the <xref:System.Windows.Forms.ListControl> class has the name of a member from the object specified to reference when obtaining the item text. If the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property does not have a member specified, the <xref:System.Windows.Forms.ListBox> then calls the <xref:System.Object.ToString%2A> method of the object to obtain the text to display in the list.


When an object is added to the collection, the <xref:System.Windows.Forms.ListBox> first checks to see if the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property of the <xref:System.Windows.Forms.ListControl> class has the name of a member from the object specified to reference when obtaining the item text. If the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property does not have a member specified, the <xref:System.Windows.Forms.ListBox> then calls the <xref:System.Object.ToString%2A> method of the object to obtain the text to display in the list.

## Examples
The following code example demonstrates how to create a <xref:System.Windows.Forms.ListBox> control that displays multiple items in columns and can have more than one item selected in the control's list. The code for the example adds 50 items to the <xref:System.Windows.Forms.ListBox> using the <xref:System.Windows.Forms.ListBox.ObjectCollection.Add%2A> method of the <xref:System.Windows.Forms.ListBox.ObjectCollection> class and then selects three items from the list using the <xref:System.Windows.Forms.ListBox.SetSelected%2A> method. The code then displays values from the <xref:System.Windows.Forms.ListBox.SelectedObjectCollection> collection (through the <xref:System.Windows.Forms.ListBox.SelectedItems%2A> property) and the <xref:System.Windows.Forms.ListBox.SelectedIndexCollection> (through the <xref:System.Windows.Forms.ListBox.SelectedIndices%2A> property). This example requires that the code is located in and called from a <xref:System.Windows.Forms.Form>.
Expand All @@ -221,8 +222,7 @@
]]></format>
</remarks>
<exception cref="T:System.SystemException">There is insufficient space available to add the new item to the list.</exception>
<exception cref="T:System.ArgumentNullException">
<paramref name="item" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentNullException"><paramref name="item" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<MemberGroup MemberName="AddRange">
Expand Down Expand Up @@ -262,9 +262,7 @@
<format type="text/markdown"><![CDATA[

## Remarks
If the <xref:System.Windows.Forms.ListBox.Sorted%2A> property of the <xref:System.Windows.Forms.ListBox> is set to `true`, the items are inserted into the list alphabetically. Otherwise, the items are inserted in the order that they occur within the array. This method is typically passed an array of <xref:System.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 <xref:System.Windows.Forms.ListBox> first checks to see if the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property of the <xref:System.Windows.Forms.ListControl> class has the name of a member from the object specified to reference when obtaining the item text. If the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property does not have a member specified, the <xref:System.Windows.Forms.ListBox> then calls the <xref:System.Object.ToString%2A> method of the object to obtain the text to display in the list. When using this method to add items to the <xref:System.Windows.Forms.ListBox>, you do not need to call the <xref:System.Windows.Forms.ListBox.BeginUpdate%2A> and <xref:System.Windows.Forms.ListBox.EndUpdate%2A> methods to optimize performance. When adding items to a <xref:System.Windows.Forms.ListBox>, it is more efficient to sort the items first and then add new items. You can use this method to add a group of items to the list or to reuse the items stored in a different <xref:System.Windows.Forms.ListBox>.


If the <xref:System.Windows.Forms.ListBox.Sorted%2A> property of the <xref:System.Windows.Forms.ListBox> is set to `true`, the items are inserted into the list alphabetically. Otherwise, the items are inserted in the order that they occur within the array. This method is typically passed an array of <xref:System.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 <xref:System.Windows.Forms.ListBox> first checks to see if the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property of the <xref:System.Windows.Forms.ListControl> class has the name of a member from the object specified to reference when obtaining the item text. If the <xref:System.Windows.Forms.ListControl.DisplayMember%2A> property does not have a member specified, the <xref:System.Windows.Forms.ListBox> then calls the <xref:System.Object.ToString%2A> method of the object to obtain the text to display in the list. When using this method to add items to the <xref:System.Windows.Forms.ListBox>, you do not need to call the <xref:System.Windows.Forms.ListBox.BeginUpdate%2A> and <xref:System.Windows.Forms.ListBox.EndUpdate%2A> methods to optimize performance. When adding items to a <xref:System.Windows.Forms.ListBox>, it is more efficient to sort the items first and then add new items. You can use this method to add a group of items to the list or to reuse the items stored in a different <xref:System.Windows.Forms.ListBox>.

## Examples
The following code example demonstrates an owner-drawn <xref:System.Windows.Forms.ListBox> by setting the <xref:System.Windows.Forms.ListBox.DrawMode%2A> property to the `OwnerDrawVariable` value and handling the <xref:System.Windows.Forms.ListBox.DrawItem> and <xref:System.Windows.Forms.ListBox.MeasureItem> events. It also demonstrates setting the <xref:System.Windows.Forms.ListBox.BorderStyle%2A> and <xref:System.Windows.Forms.ListBox.ScrollAlwaysVisible%2A> properties and using the <xref:System.Windows.Forms.ListBox.ObjectCollection.AddRange%2A> method.
Expand All @@ -277,6 +275,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: <paramref name="items" /> is <see langword="null" />.</exception>
<altmember cref="M:System.Windows.Forms.ListBox.ObjectCollection.Add(System.Object)" />
</Docs>
</Member>
Expand Down Expand Up @@ -314,6 +313,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: <paramref name="value" /> is <see langword="null" />.</exception>
<altmember cref="M:System.Windows.Forms.ListBox.ObjectCollection.Add(System.Object)" />
</Docs>
</Member>
Expand Down Expand Up @@ -388,8 +388,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">
<paramref name="value" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentNullException"><paramref name="value" /> is <see langword="null" />.</exception>
<altmember cref="M:System.Windows.Forms.ListBox.ObjectCollection.IndexOf(System.Object)" />
<altmember cref="M:System.Windows.Forms.ListBox.FindString(System.String)" />
<altmember cref="M:System.Windows.Forms.ListBox.FindStringExact(System.String)" />
Expand Down Expand Up @@ -436,6 +435,7 @@

]]></format>
</remarks>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: <paramref name="destination" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="Count">
Expand Down Expand Up @@ -578,8 +578,7 @@
]]></format>
</remarks>
<exception cref="T:System.ArgumentOutOfRangeException">The <paramref name="index" /> parameter is less than zero or greater than value of the <see cref="P:System.Windows.Forms.ListBox.ObjectCollection.Count" /> property of the <see cref="T:System.Windows.Forms.ListBox.ObjectCollection" /> class.</exception>
<exception cref="T:System.ArgumentNullException">
<paramref name="item" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentNullException"><paramref name="item" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="IsReadOnly">
Expand Down Expand Up @@ -798,6 +797,7 @@
</remarks>
<forInternalUseOnly />
<exception cref="T:System.ArrayTypeMismatchException">The array type is not compatible with the items in the <see cref="T:System.Windows.Forms.ListBox.ObjectCollection" />.</exception>
<exception cref="T:System.ArgumentNullException">.NET 5.0 and later: <paramref name="destination" /> is <see langword="null" />.</exception>
</Docs>
</Member>
<Member MemberName="System.Collections.ICollection.IsSynchronized">
Expand Down Expand Up @@ -909,8 +909,7 @@
]]></format>
</remarks>
<forInternalUseOnly />
<exception cref="T:System.ArgumentNullException">
<paramref name="item" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentNullException"><paramref name="item" /> is <see langword="null" />.</exception>
<exception cref="T:System.ArgumentException">The current <see cref="T:System.Windows.Forms.ListBox" /> has a data source.</exception>
<exception cref="T:System.SystemException">There is insufficient space available to store the new item.</exception>
</Docs>
Expand Down