方法: Windows フォーム ListView コントロール内の項目を選択するHow to: Select an Item in the Windows Forms ListView Control
この例では、Windows フォームコントロール内の項目をプログラムで選択する方法を示し ListView ます。This example demonstrates how to programmatically select an item in a Windows Forms ListView control. プログラムによって項目を選択しても、コントロールにフォーカスが自動的に変更されることはありません ListView 。Selecting an item programmatically does not automatically change the focus to the ListView control. このため、通常は項目を選択するときに項目をフォーカスとして設定する必要があります。For this reason, you will typically also want to set the item as focused when selecting an item.
例Example
this.listView1.Items[0].Focused = true;
this.listView1.Items[0].Selected = true;
me.ListView1.Items(0).Focused = True
me.ListView1.Items(0).Selected = True
コードのコンパイルCompiling the Code
この例で必要な要素は次のとおりです。This example requires:
ListView少なくとも1つの項目を含むという名前のコントロール
listView1
。A ListView control namedlistView1
that contains at least one item.System 名前空間と System.Windows.Forms 名前空間への参照。References to the System and System.Windows.Forms namespaces.