Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2004-09-19
1
Medium Priority
?
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
jcesarf earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

715 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