By using the Details view style, you can turn Listview control into awesome reporting tool in C#.Net.
Here what you need to configure
- Turn on the detailed view
- Supply heading Text
- Put the data.
The headers
You can use either Column Header object or simply configure with String and column width.
ColumnHeader headers = new ColumnHeader();
listView1.View = View.Details;
headers.Text = ” “;
headers.Width = 0;
listView1.Columns.Add(headers);
headers = new ColumnHeader();
listView1.View = View.Details;
headers.Text = “Date”;
headers.Width = 90;
listView1.Columns.Add(headers);
headers = new ColumnHeader();
headers.Text = “Account “;
headers.Width = 150;
Outing the items
You need to add subitems to items instead of passing values to Itemes. First up all we need an item object and a subitems object. Then we add the sub to item and item to Listview.
items = new ListViewItem();
sub = new ListViewItem.ListViewSubItem(items, “Date”);
sub.Text = string.Format(“{0:MM/dd/yyy}”, r[“tdate”]);
items.SubItems.Add(sub); listView1.Items.Add(items);
that’s it.
One thought on “How to use ListView control as a reporting tool in C#”