Solved

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

Posted on 2004-09-19
1
413 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now