Solved

Adding a Property to the ListView's ColumnHeader

Posted on 2004-09-23
8
229 Views
Last Modified: 2010-04-23
Hy all!

I need make a control that will have a custom text property on the columnheader collection. I was searching over the internet for one week, i don't found a way of doing this. Can anybody shows me an example (or where i can get one) for VB.Net to help me implementing this?

Thanks all!
0
Comment
Question by:regisdaniel
  • 3
  • 2
8 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
Hi regisdaniel,

something like this ?

Public Class Mycolumnheader
    Inherits ColumnHeader
    Private _extra As String

    Public Property extra() As String
        Get
            Return _extra
        End Get
        Set(ByVal Value As String)
            _extra = Value
        End Set
    End Property
End Class

implement like this

Dim h As New Mycolumnheader
        h.extra = "test"
        h.Text = "yourcolumnname"
        ListView1.Columns.Add(h)

to get the extra information from the column header use the columnclick event of the listview

Private Sub ListView1_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles ListView1.ColumnClick
        MsgBox(CType(ListView1.Columns.Item(e.Column), Mycolumnheader).extra())
    End Sub
0
 

Author Comment

by:regisdaniel
Comment Utility
Ok. But i want be able change these properties on the form editor.
How  can i do this?
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
Comment Utility
Well, luckily you don't want much ;-)

try this

Public Class mylistview2
    Inherits ListView

    Private WithEvents mColumns As New ColumnCollection

    Shadows ReadOnly Property Columns() As ColumnCollection
        Get
            Return mColumns
        End Get
    End Property

End Class

Public Class ColumnCollection
    Inherits CollectionBase
   
    Default Public Property Item(ByVal index As Integer) As Column
        Get
            Return CType(List(index), Column)
        End Get
        Set(ByVal Value As Column)
            List(index) = Value
        End Set
    End Property


    Public Function Add(ByVal value As Column) As Integer
        Dim result As Integer
        result = List.Add(value)
        AddHandler value.Changed, AddressOf OnChanged
        OnChanged(Me, New EventArgs)
        Return result
    End Function


    Public Function Add(ByVal text As String) As Column
        Dim result As New Column
        result.Text = text
        Add(result)
        Return result
    End Function


    Public Function Add(ByVal text As String, ByVal width As Integer) As Column
        Dim result As New Column
        result.Text = text
        result.Width = width
        Add(result)
        Return result
    End Function


    Public Function IndexOf(ByVal value As Column) As Integer
        Return List.IndexOf(value)
    End Function


    Public Sub Insert(ByVal index As Integer, ByVal value As Column)
        List.Insert(index, value)
        OnChanged(Me, New EventArgs)
    End Sub


    Public Sub Remove(ByVal value As Column)
        List.Remove(value)
        OnChanged(Me, New EventArgs)
    End Sub


    Public Function Contains(ByVal value As Column) As Boolean
        Return List.Contains(value)
    End Function


    Public Event Changed(ByVal sender As Object, ByVal e As EventArgs)
    Protected Friend Sub OnChanged(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent Changed(sender, e)
    End Sub

End Class


Public Class Column

    Private mText As String = "Column"
    Private mExtraText As String = "Extratext"
    Property Text() As String
        Get
            Return mText
        End Get
        Set(ByVal Value As String)
            If mText <> Value Then
                mText = Value
                OnChanged(Me, New EventArgs)
            End If
        End Set
    End Property

    Property ExtraText() As String
        Get
            Return mExtraText
        End Get
        Set(ByVal Value As String)
            If mExtraText <> Value Then
                mExtraText = Value
                OnChanged(Me, New EventArgs)
            End If
        End Set
    End Property

    Private mWidth As Integer = 100
    Property Width() As Integer
        Get
            Return mWidth
        End Get
        Set(ByVal Value As Integer)
            If mWidth <> Value Then
                mWidth = Value
                OnChanged(Me, New EventArgs)
            End If
        End Set
    End Property


    Public Event Changed(ByVal sender As Object, ByVal e As EventArgs)
    Protected Friend Sub OnChanged(ByVal sender As Object, ByVal e As EventArgs)
        RaiseEvent Changed(sender, e)
    End Sub

End Class
0
 

Author Comment

by:regisdaniel
Comment Utility
Ok Ronald! Thanks very much!!!

But, when I insert the control on a Form, everything works fine, but, when i reload the form, all colums have gone. What's wrong?

Thanks!!!
0
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
Strange, I'll have a look ?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Merging PDFs with VB.NET 10 30
how to add field in my script 2 24
How to open a link from vb.net app 3 9
Round up to 100% in .NET 10 41
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

10 Experts available now in Live!

Get 1:1 Help Now