如何列标题添加到C#一个ListView [英] How to add Column header to a ListView in C#

查看:1307
本文介绍了如何列标题添加到C#一个ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与没有列ListView控件。

这是一个List

 列表<串GT; MYLIST =新的List<串GT;();

我需要为每个列表创建列 MYLIST 的ListView 有一个序列号的另一列沿着项目

例如,如果 MYLIST 包含A,B,C

然后列表视图会像

我知道,我们可以用做的foreach 循环像

  listView1.Columns.Add(S.No)
的for(int i = 0; I< MyList.Count;我++)
   {
      listView1.Columns.Add(MYLIST [I])
   }

但有什么办法做到这一点使用 LINQ LAMBDA防爆pression


解决方案

  MyList.ForEach(名称=> listView1.Columns.Add(名));

i'm having a ListView control with no columns.

an a list

List<String> MyList=new List<string>();

i need to create columns for each list MyList item in the ListView along with one another column for Serial Number.

For example if MyList contains "A", "B" ,"C"

then the list view will be like

I know that we can do this using for or foreach loop like

listView1.Columns.Add("S.No")
for(int i=0;i<MyList.Count;i++)
   {
      listView1.Columns.Add(MyList[i])
   }

but is there any way to do this using LINQ or LAMBDA Expression?

解决方案

MyList.ForEach(name => listView1.Columns.Add(name));

这篇关于如何列标题添加到C#一个ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆