How to use ListView control as a reporting tool in C#


By using the Details view style, you can turn Listview control into awesome  reporting tool in C#.Net.

Here what you need to configure

  1. Turn on the detailed view
  2. Supply heading Text
  3. 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.

 

 

 

 

 

1 thought on “How to use ListView control as a reporting tool in C#

  1. Pingback: How to change font of listview items at runtime in C# | DeveloperM – A developer's Manual

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.