ListView listView1 = new ListView(); this.Controls.Add(listView1); listView1.Dispose();
using System; using System.Windows.Forms; namespace ListViewDemo { public partial class MainForm : Form { private ListView myListView = new ListView(); public MainForm() { InitializeComponent(); // Configure the ListView control myListView.View = View.Details; myListView.Columns.Add("ID", 50); myListView.Columns.Add("Name", 100); myListView.Columns.Add("Age", 50); // Add some sample data myListView.Items.Add(new ListViewItem(new string[] { "1", "John", "25" })); myListView.Items.Add(new ListViewItem(new string[] { "2", "Jane", "30" })); myListView.Items.Add(new ListViewItem(new string[] { "3", "Bob", "40" })); // Add the control to the form this.Controls.Add(myListView); } protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); // Dispose of the ListView control myListView.Dispose(); } } }This example creates a form with a ListView control that displays sample data. When the form is closed, the Dispose() method is called to release the resources used by the control. The System.Windows.Forms namespace is part of the .NET Framework Class Library.