本文整理汇总了C#中System.Windows.Forms.SelectionMode枚举的典型用法代码示例。如果您正苦于以下问题:C# SelectionMode枚举的具体用法?C# SelectionMode怎么用?C# SelectionMode使用的例子?那么, 这里精选的枚举代码示例或许可以为您提供帮助。
在下文中一共展示了SelectionMode枚举的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeMyListBox
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;
}