如何在C#winform中将列表项添加到ListView? [英] How to add list items to a ListView in C#winform?
本文介绍了如何在C#winform中将列表项添加到ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个对象列表.我想将这些项目添加到ListView.我正在尝试逐行添加每个列表项,但是格式非常糟糕,应该采用正确的表格类型格式.
I have a list of objects. I want to add these items to a ListView. I'm trying to add each list item row wise but format is very bad, it should be in proper table type format.
List<string> lst = new List<string>();
lst.Add("John dsfsfsdfs " + "1" + 100);
lst.Add("Smith sdfsdfsdfs" + "2" + 120);
lst.Add("Cait dsffffffffffffffffffffff" + "3" + 97);
lst.Add("Irene" + "4" + 100);
lst.Add("Ben" + "5" + 100);
lst.Add("Deniel jjhkh " + "6" + 88);
foreach(string pl in lst)
{
listView1.Items.Add(pl);
}
项目不可见,并且应采用正确的格式.
Items are not visible and it should be in proper format.
推荐答案
使其成为多列:
1)将ListView设置为Details模式:
To make it multicolumn:
1) set the ListView into Details mode:
listView1.View = View.Details;
2)设置您的三列:
listView1.Columns.Add("Column1Name");
listView1.Columns.Add("Column2Name");
listView1.Columns.Add("Column3Name");
3)添加您的物品:
listView1.Items.Add(new ListViewItem(new string[]{"John dsfsfsdfs ", "1" , "100"}));
4)要使其更加可见,请尝试:
4) To make it more viewable try:
listView1.GridLines = true;
5)隐藏列标题:
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
这篇关于如何在C#winform中将列表项添加到ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文