Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding a Property to the ListView's ColumnHeader

Posted on 2004-09-23
8
Medium Priority
?
241 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
[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
  • 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

618 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