Click here to Skip to main content
15,881,173 members
Articles / Programming Languages / Visual Basic
Article

A simple extension to the ListView object (in report mode)

Rate me:
Please Sign up or sign in to vote.
2.34/5 (15 votes)
22 Apr 20041 min read 63.2K   340   16   1
A simple extension to the ListView object (in report mode)

Introduction

Hello and thanks for downloading this utility. Lvx (Listviewextra) is a simple extension to the regular ListView (in detail mode) of Windows controls. The purpose of this enhancement is to sort by any column, generate a print out, open and save, select, add, and remove items, all in one control.

I have made the actual ListView, PageSetupDialog and PrintDocument objects transparent to you (i.e.: you can still access all the usual methods). So you can implement your own code or use the extra ones:

*Selected item index is returned from the control in lvx.index.

Example (for you to implement in your code)

VB
Private Sub Delete_Click(ByVal sender _
  As System.Object, ByVal e As System.EventArgs) Handles Delete.Click

    Lvx1.delete(lvx1.index)
End Sub
VB
addcolumn(text As String, width As Integer, datatype As String)

Notes:

  1. Column text alignment is to the left except for decimals.
  2. There are 3 data types that you must provide when you initialize the control:
    • "s" for String
    • "d" for Decimal
    • "dt" for Date

*** This pre-assignment in building the control is necessary when sorting.

Example:

VB
Sub columns()
    Lv.addcolumn("date", 80, "dt")
    Lv.addcolumn("payee", 80, "s")
    Lv.addcolumn("category", 80, "s")
    Lv.addcolumn("Description", 80, "s")
    Lv.addcolumn("details", 80, "s")
    Lv.addcolumn("Expense", 80, "d")
    Lv.addcolumn("Income", 80, "d")
End Sub

* fillwith (array(containing the item and its subitems))

Example:

VB
Structure itm
    Dim dates As Date
    Dim payee As String
    Dim expense As Decimal
    Dim income As Decimal
End Structure

Sub additem()
    Dim item As itm
    item.dates="01/01/2005"
    item.payee="microsoft"
    item.expense=£1050.99
    dim t(4) as string
    t(1)=item.dates.tostring
    t(2)=item.payee.tostring
    t(3)=item.expense.tostring
    t(4)=item.income.tostring
    lvx1.fillwith(t)
End Sub

Do Not use t(0).

Note: t(0) will be assigned the item's index by lvx.

  • spreview

    short for show print preview.

  • open (filename.txt As String)

    filename must have the extension 'txt'.

  • save (filename.txt As String)

    filename must have the extension 'txt'.

  • print

    prints the contents of the ListView.

Note: to display or delete the fields of a selected item in the demo included, I've associated a context menu with the ListView.

I hope you find my work useful.. Any feedback or ideas will be much appreciated. Please email me at london_man_46@yahoo.co.uk. Thanks.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralThanX Pin
Hossein Narimani Rad23-Apr-07 2:32
Hossein Narimani Rad23-Apr-07 2:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.