C# ListView Details使用指南

private void  InitializeListView()
{
this.ListView1 = new System.Windows.Forms.ListView();

// Set properties such as BackColor and DockStyle and Location.
this.ListView1.BackColor = System.Drawing.SystemColors.Control;
this.ListView1.Dock = System.Windows.Forms.DockStyle.Top;
this.ListView1.Location = new System.Drawing.Point(0, 0);
this.ListView1.Size = new System.Drawing.Size(292, 130);
this.ListView1.View = System.Windows.Forms.View.Details;
this.ListView1.HideSelection = false;

// Allow the user to select multiple i tems.
this.ListView1.MultiSelect = true;

// Show CheckBoxes in the ListView.
this .ListView1.CheckBoxe s = true;

//Set the column headers and populate the columns.
ListView1.HeaderStyle  = ColumnHeaderStyle.Nonclickable ;

ColumnHeader columnHeader1 = new ColumnHeader();
columnHeader1.Text = "Breakfast Choices";
columnHeader1.TextAlign = HorizontalAlignment.Left;
columnHeader1.Width = 146;

ColumnHeader columnHeader2 = new ColumnHeader();
columnHeader2.Text = "Price Each";
columnHeader2.TextAlign = HorizontalAlignment.Center;
columnHeader2.Width = 142;

this.ListView1.Columns.Add(columnHeader1);
this.ListView1.Columns.Add(columnHeader2);

string[] foodList = new string[]{"Juice", "Coffee",
"Cereal & Milk", "Fruit Plate", "Toast & Jelly",
"Bagel & Cream Cheese"};

string[] foodPrice = new string[]{"1.09", "1.09", "2.19",
"2.79", "2.09", "2.69"};

int count;

// Members are added one at a time, so call BeginUpdate to ensure
// the list is painted only once, rather than as each list item is added.
ListView1.BeginUpdate();

for(count = 0; count < foodList.Length; count++)
{
ListViewItem listItem = new ListViewItem(foodList[count]);
listItem.SubItems.Add(foodPrice[c ount]);
ListView1.Items.Add(listItem);
}

//Call EndUpdate when you finish adding items to the ListView.
ListView1.EndUpdate();
this.Controls.Add(this.ListView1);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值