如何:访问 Windows 窗体 ComboBox 控件、ListBox 控件或 CheckedListBox 控件中的特定项

访问 Windows 窗体组合框、列表框或复选列表框中的特定项是一项基本任务。 它使您可以编程方式确定列表中任意给定位置处的内容。

访问特定项

  • 使用指定项的索引查询 Items 集合:

    Private Function GetItemText(i As Integer) As String
       ' Return the text of the item using the index:
       Return ComboBox1.Items(i).ToString
    End Function
    
    private string GetItemText(int i)
    {
       // Return the text of the item using the index:
       return (comboBox1.Items[i].ToString());
    }
    
    private String GetItemText(int i) 
    {
       // Return the text of the item using the index:
       return comboBox1.get_Items().get_Item( i).ToString() ;
    }
    
    private:
       String^ GetItemText(int i)
       {
          // Return the text of the item using the index:
          return (comboBox1->Items->Item[i]->ToString());
       }
    

请参见

参考

ComboBox

ListBox

CheckedListBox

其他资源

用于列出选项的 Windows 窗体控件