次の方法で共有


方法: Windows フォーム コンボ ボックス、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());
       }
    

こちらも参照ください