Solved

Inherited ListView Control with a Custom Text Field in the ColumnHeader Collection

Posted on 2004-09-19
1
419 Views
Last Modified: 2012-06-27
Hi all!

I need to make a custom listview control that has a custom textfield in each column that i create. This field will be filled by the end programmer when he uses my control, that need this information (on each column) to make some calculations.

I tried to create a inherited ColumnHeaderObject, that has a new property that i use to set what i want. (See code below).
When I insert my NewControl on a form, and Add Columns to It, everthing shows to be fine, but, when i close the form and reopen it, the columns previosly declared was not showed. The listview looks like if was cleared, but the objects are declared on form.

Does anybody can help me solving this?
Thanks all!

'Inherited ColumnHeaderClass that declares my CustomField called mField.
Public Class ColumnHeaderXP
    Inherits ColumnHeader

    Private mField As String

    Public Property Field() As String
        Get
            Return mField
        End Get
        Set(ByVal Value As String)
            mField = Value
        End Set
    End Property

End Class

'My ColumnHeaderXPCollection that i use to work with my usercreated ColumnHeader
Public Class ColumnHeaderXPCollection
    Inherits CollectionBase

    Public Event Invalidate()

    Protected Sub OnInvalidate()
        RaiseEvent Invalidate()
    End Sub

    Default Public ReadOnly Property Item(ByVal Index As Integer) As ColumnHeaderXP
        Get
            Return CType(list.Item(Index), ColumnHeaderXP)
        End Get
    End Property

    Public Sub Add(ByVal Field As String)
        Dim col As New ColumnHeaderXP
        col.Text = Field
        col.Field = Field
        list.Add(col)
    End Sub

    Public Sub Add(ByVal Field As String, ByVal Width As Integer)
        Dim col As New ColumnHeaderXP
        col.Text = Field
        col.Field = Field
        col.Width = Width
        list.Add(col)
    End Sub

    Public Sub Add(ByVal Text As String, ByVal Field As String)
        Dim col As New ColumnHeaderXP
        col.Text = Text
        col.Field = Field
        list.Add(col)
    End Sub

    Public Sub Add(ByVal Text As String, ByVal Field As String, ByVal Width As Integer)
        Dim col As New ColumnHeaderXP
        col.Text = Text
        col.Field = Field
        col.Width = Width
        list.Add(col)
    End Sub

    Public Sub Add(ByVal Item As ColumnHeaderXP)
        list.Add(Item)
    End Sub

    Protected Overrides Sub OnRemoveComplete(ByVal index As Integer, ByVal value As Object)
        OnInvalidate()
    End Sub

    Protected Overrides Sub OnInsertComplete(ByVal index As Integer, ByVal value As Object)
        OnInvalidate()
    End Sub

    Protected Overrides Sub OnSetComplete(ByVal index As Integer, ByVal oldValue As Object, ByVal newValue As Object)
        OnInvalidate()
    End Sub

    Protected Overrides Sub OnClearComplete()
        OnInvalidate()
    End Sub
End Class

'My control itself
Option Strict On

Imports System.ComponentModel
Imports System.Reflection

Public Class ListViewXP
    Inherits System.Windows.Forms.ListView

    Private WithEvents mColumns As ColumnHeaderXPCollection

    'Constructor
    Public Sub New()
        mColumns = New ColumnHeaderXPCollection
        View = View.Details
        FullRowSelect = True
        MultiSelect = False
    End Sub

    'Load the columns
    Private Sub DataBind()

        Clear()

        Dim Field As Integer

        ' load the column headers
        For Field = 0 To mColumns.Count - 1
            MyBase.Columns.Add(mColumns(Field))
        Next

    End Sub

    'User defined Property Column
    Public Shadows ReadOnly Property Columns() As ColumnHeaderXPCollection
        Get
            Return mColumns
        End Get
    End Property

    'When a Add or Change a Column, This event is Fired
    Private Sub mItems_Invalidate() Handles mColumns.Invalidate
        DataBind()
    End Sub

End Class

Thaks all!
0
Comment
Question by:regisdaniel
1 Comment
 
LVL 1

Accepted Solution

by:
jcesarf earned 500 total points
ID: 12108556
Hi!

1) Create a module that will export your mColumn object from the class.

Module modGlobal
    Friend mColumns As ColumnHeaderXPCollection
End Module


2) On your ListViewXp Class, add the folowing line to your constructor:

    'Constructor
    Public Sub New()
        mColumns = New ColumnHeaderXPCollection
        modGlobal.mColumns = Me.mColumns  '***This line
        View = View.Details
        FullRowSelect = True
        MultiSelect = False
    End Sub

3) Create a contructor on your ColumnHeaderXP Class
    Public Sub New()
        modGlobal.mColumns.Add(Me)
    End Sub

4) Test your project. It shoud work now!!!


Bye!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB: Convert 2 dates to specific format 24 54
VB.net and sql server 4 53
DataGridView / get bound table name? 8 35
VB.net Open video relating to control 2 29
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question