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.
To make it multicolumn:
1) set the ListView into Details mode:
listView1.View = View.Details;
2)set up your three columns:
listView1.Columns.Add("Column1Name");
listView1.Columns.Add("Column2Name");
listView1.Columns.Add("Column3Name");
3) add your items:
listView1.Items.Add(new ListViewItem(new string[]{"John dsfsfsdfs ", "1" , "100"}));
4) To make it more viewable try:
listView1.GridLines = true;
5) To hide columns headers:
listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
You can use ListViewItem
directly to create an item with subitems (-> "tabular") instead of just adding strings to your ListView:
listView1.Items.Add(new ListViewItem (new[]{"John dsfsfsdfs", "1", "100"}));
listView1.Items.Add(new ListViewItem (new[]{"Smith sdfsdfsdfs", "2", "120"}));
listView1.Items.Add(new ListViewItem (new[]{"Cait dsffffffffffffffffffffff", "3", "97"}));
listView1.Items.Add(new ListViewItem (new[]{"Irene", "4", "100"}));
listView1.Items.Add(new ListViewItem (new[]{"Ben", "5, "100"}));
listView1.Items.Add(new ListViewItem (new[]{"Deniel jjhkh", "6", "88"}));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With