Solved

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

Posted on 2004-09-19
1
412 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 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

15 Experts available now in Live!

Get 1:1 Help Now