SelectionMode 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定清單方塊的選取行為。
public enum class SelectionMode
[System.Runtime.InteropServices.ComVisible(true)]
public enum SelectionMode
public enum SelectionMode
[<System.Runtime.InteropServices.ComVisible(true)>]
type SelectionMode =
type SelectionMode =
Public Enum SelectionMode
- 繼承
- 屬性
欄位
MultiExtended | 3 | 有多種項目可供選取,且使用者可以利用 SHIFT、CTRL 和方向鍵選取。 |
MultiSimple | 2 | 可以選取多重項目。 |
None | 0 | 沒有可選取項目。 |
One | 1 | 只能選取一個項目。 |
範例
下列範例示範如何使用 GetSelected 方法來判斷 中 ListBox 選取的專案,以選取未選取的專案,並取消選取選取的專案。 此範例也會示範如何使用 SelectionMode 屬性讓 ListBox 擁有多個選取的專案,並使用 Sorted 屬性來示範如何自動排序專案中 ListBox 的專案。 這個範例假設 ListBoxlistBox1
名為 的 已加入表單,而且 InitializeMyListBox
範例中所定義的方法是從表單的 事件呼叫 Load 。
private:
void InitializeMyListBox()
{
// Add items to the ListBox.
listBox1->Items->Add( "A" );
listBox1->Items->Add( "C" );
listBox1->Items->Add( "E" );
listBox1->Items->Add( "F" );
listBox1->Items->Add( "G" );
listBox1->Items->Add( "D" );
listBox1->Items->Add( "B" );
// Sort all items added previously.
listBox1->Sorted = true;
// Set the SelectionMode to select multiple items.
listBox1->SelectionMode = SelectionMode::MultiExtended;
// Select three initial items from the list.
listBox1->SetSelected( 0, true );
listBox1->SetSelected( 2, true );
listBox1->SetSelected( 4, true );
// Force the ListBox to scroll back to the top of the list.
listBox1->TopIndex = 0;
}
void InvertMySelection()
{
// Loop through all items the ListBox.
for ( int x = 0; x < listBox1->Items->Count; x++ )
{
// Select all items that are not selected,
// deselect all items that are selected.
listBox1->SetSelected( x, !listBox1->GetSelected( x ) );
}
listBox1->TopIndex = 0;
}
private void InitializeMyListBox()
{
// Add items to the ListBox.
listBox1.Items.Add("A");
listBox1.Items.Add("C");
listBox1.Items.Add("E");
listBox1.Items.Add("F");
listBox1.Items.Add("G");
listBox1.Items.Add("D");
listBox1.Items.Add("B");
// Sort all items added previously.
listBox1.Sorted = true;
// Set the SelectionMode to select multiple items.
listBox1.SelectionMode = SelectionMode.MultiExtended;
// Select three initial items from the list.
listBox1.SetSelected(0,true);
listBox1.SetSelected(2,true);
listBox1.SetSelected(4,true);
// Force the ListBox to scroll back to the top of the list.
listBox1.TopIndex=0;
}
private void InvertMySelection()
{
// Loop through all items the ListBox.
for (int x = 0; x < listBox1.Items.Count; x++)
{
// Determine if the item is selected.
if(listBox1.GetSelected(x) == true)
// Deselect all items that are selected.
listBox1.SetSelected(x,false);
else
// Select all items that are not selected.
listBox1.SetSelected(x,true);
}
// Force the ListBox to scroll back to the top of the list.
listBox1.TopIndex=0;
}
Private Sub InitializeMyListBox()
' Add items to the ListBox.
listBox1.Items.Add("A")
listBox1.Items.Add("C")
listBox1.Items.Add("E")
listBox1.Items.Add("F")
listBox1.Items.Add("G")
listBox1.Items.Add("D")
listBox1.Items.Add("B")
' Sort all items added previously.
listBox1.Sorted = True
' Set the SelectionMode to select multiple items.
listBox1.SelectionMode = SelectionMode.MultiExtended
' Select three initial items from the list.
listBox1.SetSelected(0, True)
listBox1.SetSelected(2, True)
listBox1.SetSelected(4, True)
' Force the ListBox to scroll back to the top of the list.
listBox1.TopIndex = 0
End Sub
Private Sub InvertMySelection()
Dim x As Integer
' Loop through all items the ListBox.
For x = 0 To listBox1.Items.Count - 1
' Determine if the item is selected.
If listBox1.GetSelected(x) = True Then
' Deselect all items that are selected.
listBox1.SetSelected(x, False)
Else
' Select all items that are not selected.
listBox1.SetSelected(x, True)
End If
Next x
' Force the ListBox to scroll back to the top of the list.
listBox1.TopIndex = 0
End Sub
備註
這類類別會使用此列舉,例如 ListBox 和 CheckedListBox 。