• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#ListViewDetails使用指南

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

发现网上关于ListView的视频教程大多没讲Details用法,找了许久

发现还是msdn讲的最好

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 items.
this.ListView1.MultiSelect = true;

// Show CheckBoxes in the ListView.
this.ListView1.CheckBoxes = 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[count]);
ListView1.Items.Add(listItem);
}

//Call EndUpdate when you finish adding items to the ListView.
ListView1.EndUpdate();
this.Controls.Add(this.ListView1);
}


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#实现敏感词过滤发布时间:2022-07-10
下一篇:
CefSharp-基于C#的客户端开发框架技术栈开发全记录发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap