Solved

Adding a Property to the ListView's ColumnHeader

Posted on 2004-09-23
8
233 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
ID: 12140854
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
ID: 12142337
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
ID: 12143928
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
ID: 12157185
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
ID: 12158283
Strange, I'll have a look ?
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.Net WebRequest Code from JSON curl 7 50
Generate Numbers in JQuery file 11 66
How to seperate number and letters from a string 3 22
DataGridView / get bound table name? 8 24
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…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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