VB ListView Sample Project
VB ListView Sample Project
Let's put together the members of the ListView control to create a sample application that populates the control and enumerates its items. The sample application of this section is the ListViewDemo project. The application's form, shown in Figure 4.31, contains a ListView control whose items can be displayed in all possible views, depending on the status of the RadioButton controls in the List Style section on the right side of the form. The control's headers and their widths were set at design time through the ColumnHeader Collection Editor, as explained earlier. To populate the ListView control, click the Populate List button, whose code is shown next. The code creates a new ListViewItem object for each item to be added. Then it calls the Add method of the SubItems collection to add the item's subitems (contact, phone, and fax numbers). After the ListViewItem has been set up, it's added to the control via the Add method of its Items collection.
Figure 4.31 - ListView Sample Project demonstrates the basic members of the ListView control. Listing 4.46 shows the statements that insert the first two items in the list. The remaining items are added by using similar statements, which need not be repeated here. The sample data I used in the ListViewDemo application came from the Northwind sample database. Listing 4.46: Populating a ListView Control Dim LItem As New ListViewItem() LItem.Text = "Alfred's Futterkiste" LItem.SubItems.Add("Anders Maria") LItem.SubItems.Add("030-0074321") LItem.SubItems.Add("030-0076545")
LItem.ImageIndex = 0 ListView1.Items.Add(LItem) LItem = New ListViewItem() LItem.Text = "Around the Horn" LItem.SubItems.Add("Hardy Thomas") LItem.SubItems.Add("(171) 555-7788") LItem.SubItems.Add("(171) 555-6750") LItem.ImageIndex = 0 ListView1.Items.Add(LItem)
Telephone (171) 555-7788 FAX (171) 555-6750 The code in Listing 4.47 uses a For. . .Next loop to iterate through the items of the control. You can also set up a For Each. . .Next loop, as shown here: Dim LI As ListViewItem For Each LI In ListView1.Items { access the current item through the LI variable} Next Table of Contents VB.NET TextBox Control Text-Manipulation Properties of TextBox Control Text-Selection Properties of TextBox Control Text-Selection Methods of TextBox Control The TextEditor Project Using VB.NET TextBox Control Capturing/Handling Keystrokes Auto-complete Properties of a VB.NET TextBox Control The ListBox, CheckedListBox, and ComboBox Controls Adding, Removing and Accessing Items from the ListBox Control's Item Collection Selecting Items from a ListBox Control Adding and Removing Items from a ListBox Control Searching the ListBox Control VB.NET ComboBox Control Adding Items to a ComboBox at Runtime The ScrollBar and TrackBar Controls in VB 2008 The CommonDialog Controls in VB.NET 2008 The ColorDialog Control in VB 2008 The FontDialog Control in VB 2008 The OpenDialog and SaveDialog Controls The FolderBrowserDialog Control The RichTextBox Control in VB.NET 2008 Text Manipulation and Formatting Properties of RichTextBox Control Advanced Editing Features & Searching in a RichTextBox Control Handling URLs and Displaying a Formatted Directory Listing in the RichTextBox Document The RichTextBoxPad Project (VB.NET RichTextBox) - VB 2008 Understanding the ListView, TreeView, and ImageList Controls Tree and List Structures of TreeView Control The ImageList Control in Visual Basic.NET 2008 The TreeView Control in Visual Basic.NET 2008 Adding Nodes to a TreeView Control at Design Time Adding Nodes to a TreeView Control at Runtime TreeView Example Exercise 1 TreeViewDemo - The Globe Example Scanning the TreeView Control The ListView Control ListView Items and Subitems The Items Collection and The SubItems Collection of The ListView Control The ListView Sample Project - VB.NET 2008 Sorting the ListView Control The CustomExplorer Project using ListView and TreeView Controls