This documentation is archived and is not being maintained.

Accessing Specific Items in a Windows Forms ComboBox, ListBox, or CheckedListBox Control

Visual Studio .NET 2003

Accessing specific items in a Windows Forms combo box, list box, or checked list box is an essential task. It allows you to programmatically determine what is in a list, at any given position.

To access a specific item

  • Query the Items collection using the index of the specific item:
    ' Visual Basic
    Private Function GetItemText(i As Integer) As String
       ' Return the text of the item using the index:
       Return ComboBox1.Items(i).ToString
    End Function
    
    // C#
    private string GetItemText(int i)
    {
       // Return the text of the item using the index:
       return (comboBox1.Items[i].ToString());
    }
    
    // C++
    private:
       String* GetItemText(int i)
       {
          // Return the text of the item using the index:
          return (comboBox1->Items->Item[i]->ToString());
       }
    

See Also

ComboBox Class | ListBox Class | CheckedListBox Class | Windows Forms Controls Used to List Options

Show: