HOW TO:在 Windows Form 的 ComboBox、ListBox 或 CheckedListBox 控制項中存取特定的項目
更新:2007 年 11 月
在 Windows Form 下拉式方塊、清單方塊或選取的清單方塊中存取指定的項目是一項基本工作。您可利用程式設計方式決定指定位置的清單內容。
若要存取指定項目
使用指定項目的索引來查詢 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()); }