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

访问 Windows 窗体组合框、列表框或选中列表框中的特定项是一项基本任务。 它使你能够以编程方式确定列表中的内容(在任何给定位置)。

访问特定项

  1. 通过特定项的索引查询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->Items->Item[i]->ToString());
       }
    

另请参阅