65.9K
CodeProject is changing. Read more.
Home

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

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.34/5 (13 votes)

Apr 15, 2004

1 min read

viewsIcon

63260

downloadIcon

340

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.