How to Put ListView Headers in a Notepad Using VB6

How to Put ListView Headers in a Notepad Using VB6 thumbnail
The Notepad computer application works much the same way as a physical notepad.

The Visual BASIC ListView is a control that displays data in list form. The ListView can display information as a list of small or large icons, a small icon with text to the right of it, or a report format in which the text of each "subitem" is displayed to the right under each column header. These views may sound familiar to you as this is how the Windows Explorer displays folder and file information. The information displayed in the ListView can be viewed, selected, re-ordered, updated or exported to another application such as Notepad or Excel.

Instructions

    • 1

      Open a new Visual BASIC Standard EXE project. Add the ListView object to the toolbox by clicking "Project," "Components" and clicking the check box next to "Microsoft Windows Common Controls 6.0 (SP6)." Select the ListView object from the toolbox and click on the default "Form1." Rename "Form1" to something more meaningful such as "frmMain" and the newly created ListView to "lvCustomer."

    • 2

      Add a button to "frmMain" and set the caption to "Export." In the "Form_Load" event, populate "lvCustomer" with customer data either by hard-coding or retrieving the data from a database. Add the column headers the same way. A basic example of adding a column header is "lvCustomer.ColumnHeaders.Add 1,"CustName","Name"." This line of code indicates that the first column header will have a key of "CustName" and a value displayed to the user of "Name." A basic example of adding a row of data to the "lvCustomer" is "lvCustomer.ListItems.Add 1, , "John Smith"." This line of code creates a row of data in the first column, with no key and a value of "John Smith."

    • 3

      Retrieve the column headers by looping through the ListView ColumnHeader items.
      For i = 1 To lvCustomer.ColumnHeaders.Count
      sHeader = sHeader + lvCustomer.ColumnHeaders.Item(i).Text + vbTab
      Next
      This code loops through each ColumnHeader and stores the value in the string variable "sHeader" followed by a tab space character.

    • 4

      Create a text file to store the ColumnHeader data with the Microsoft FileSystemObject. The following code creates a text file named "output.txt" and saves the value of the string variable "sHeader" to that file:
      Dim FSO As New FileSystemObject
      Set newFIle = FSO.CreateTextFile("c:\temp\output.txt", True, False)
      newFIle.Write (sHeader)

    • 5

      Open the contents of the new "output.txt" file in Notepad with the "Shell" command:
      dblNotePadID = Shell("Notepad c:\temp\output.txt")

Related Searches:

References

  • Photo Credit Jupiterimages/Photos.com/Getty Images

Comments

Related Ads

Featured