Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

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

0.00/5 (No votes)
22 Apr 2004 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)

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

    Lvx1.delete(lvx1.index)
End Sub
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:

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:

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