本文整理汇总了C#中System.Windows.Forms.ListViewItem.Selected属性的典型用法代码示例。如果您正苦于以下问题:C# ListViewItem.Selected属性的具体用法?C# ListViewItem.Selected怎么用?C# ListViewItem.Selected使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.ListViewItem
的用法示例。
在下文中一共展示了ListViewItem.Selected属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializeListView
private void InitializeListView()
{
// Set up the inital values for the ListView and populate it.
this.ListView1 = new ListView();
this.ListView1.Dock = DockStyle.Top;
this.ListView1.Location = new System.Drawing.Point(0, 0);
this.ListView1.Size = new System.Drawing.Size(292, 130);
this.ListView1.View = View.Details;
this.ListView1.FullRowSelect = true;
string[] breakfast = new string[]{"Continental Breakfast",
"Pancakes and Sausage", "Denver Omelet", "Eggs & Bacon",
"Bagel & Cream Cheese"};
string[] breakfastPrices = new string[]{"3.09", "4.09",
"4.19", "4.79", "2.09"};
PopulateMenu("Breakfast", breakfast, breakfastPrices);
}
private void PopulateMenu(string meal,
string[] menuItems, string[] menuPrices)
{
ColumnHeader columnHeader1 = new ColumnHeader();
columnHeader1.Text = meal + " Choices";
columnHeader1.TextAlign = HorizontalAlignment.Left;
columnHeader1.Width = 146;
ColumnHeader columnHeader2 = new ColumnHeader();
columnHeader2.Text = "Price";
columnHeader2.TextAlign = HorizontalAlignment.Center;
columnHeader2.Width = 142;
this.ListView1.Columns.Add(columnHeader1);
this.ListView1.Columns.Add(columnHeader2);
for(int count=0; count < menuItems.Length; count++)
{
ListViewItem listItem =
new ListViewItem(menuItems[count]);
listItem.SubItems.Add(menuPrices[count]);
ListView1.Items.Add(listItem);
}
// Use the Selected property to select the first item on
// the list.
ListView1.Focus();
ListView1.Items[0].Selected = true;
}
private void Button1_Click(System.Object sender, System.EventArgs e)
{
// Create new values for the ListView, clear the list,
// and repopulate it.
string[] lunch = new string[]{"Hamburger", "Grilled Cheese",
"Soup & Salad", "Club Sandwich", "Hotdog"};
string[] lunchPrices = new string[]{"4.09", "5.09", "5.19",
"4.79", "2.09"};
ListView1.Clear();
PopulateMenu("Lunch", lunch, lunchPrices);
Button1.Enabled = false;
}