D
dt
Hi All,
I have been looking at this for a little while now and can't figure it out.
I was hoping someone could help.
I needed to have an aditional property for the ColumnHeader object contained
in the ListView Columns collection. I needed this property to map ListView
columns to DataTable columns for a suedo databinding function. I though
perhaps inherit from the listview and ColumnHeader objects. Here are the
steps and code:
STEP 1: Create a ColumnHeader object that inherits from ColumnHeader with
the additional property
Public Class DataBoundColumnHeader
Inherits ColumnHeader
Private m_BoundColumn As String 'new property
Public Sub New()
MyBase.New()
End Sub
<Category("Data")> _
Public Property BoundColumn() As String
Get
Return Me.m_BoundColumn
End Get
Set(ByVal Value As String)
Me.m_BoundColumn = Value
End Set
End Property
End Class
STEP 2: Create a ColumnHeaderCollection object that inherits from
ColumnHeaderCollection and shadows functions which assign and retrieve my
custom DataBoundColumnHeader object
Public Class DataBoundColumnHeaderCollection
Inherits ListView.ColumnHeaderCollection
Public Sub New(ByVal Owner As ListView)
MyBase.New(Owner)
End Sub
Default Public Shadows ReadOnly Property Item(ByVal Index As
Integer) As DataBoundColumnHeader
Get
Return CType(MyBase.Item(Index), DataBoundColumnHeader)
End Get
End Property
Public Shadows Function Add(ByVal Column As DataBoundColumnHeader)
As Integer
Return MyBase.Add(Column)
End Function
Public Shadows Function Add(ByVal Text As String, ByVal width As
Integer, _
ByVal TextAlign As HorizontalAlignment) As DataBoundColumnHeader
Return CType(MyBase.Add(Text, width, TextAlign),
DataBoundColumnHeader)
End Function
'This should be public: but a conversion type error occurs
Private Shadows Sub AddRange(ByVal Values() As
DataBoundColumnHeader)
MyBase.AddRange(Values)
End Sub
End Class
STEP 3: Create a ListView object that inherits from ListView shadowing the
Columns property to accept my ColumnHeaderCollection
Public Class DataBoundListView
Inherits System.Windows.Forms.ListView
Private m_DataBoundColumns As New
DataBoundColumnHeaderCollection(Me)
<Category("Behavior"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
_
Public Shadows ReadOnly Property Columns() As
DataBoundColumnHeaderCollection
Get
Return m_DataBoundColumns
End Get
End Property
End Class
THE PROBLEM:
PROBLEM 1: This will not work unless the shadowed function AddRange is
private and not public: The error is a typeconversion error
PROBLEM 2: When I add the DataBoundListViewControl to a form and add some
columns I get the following automatically generated code:
'Notice the System.Windows.Forms.ColumnHeader object
Me.DataBoundListView1.Columns.AddRange(New
System.Windows.Forms.ColumnHeader() {Me.DataBoundColumnHeader9,
Me.DataBoundColumnHeader10})
Me.DataBoundListView1.Location = New System.Drawing.Point(72, 104)
Me.DataBoundListView1.Name = "DataBoundListView1"
Me.DataBoundListView1.TabIndex = 0
Me.DataBoundListView1.View = System.Windows.Forms.View.Details
The automatic code generator creates an array of new ColumnHeader objects
but assigns DataBoundColumnHeader ojects to items in that array. This is a
little confusing. I really prefer it creates an array of
DataBoundColumnHeader objects and then I could make my Private AddRange,
Public.
Thanks in advance,
Demetrio
I have been looking at this for a little while now and can't figure it out.
I was hoping someone could help.
I needed to have an aditional property for the ColumnHeader object contained
in the ListView Columns collection. I needed this property to map ListView
columns to DataTable columns for a suedo databinding function. I though
perhaps inherit from the listview and ColumnHeader objects. Here are the
steps and code:
STEP 1: Create a ColumnHeader object that inherits from ColumnHeader with
the additional property
Public Class DataBoundColumnHeader
Inherits ColumnHeader
Private m_BoundColumn As String 'new property
Public Sub New()
MyBase.New()
End Sub
<Category("Data")> _
Public Property BoundColumn() As String
Get
Return Me.m_BoundColumn
End Get
Set(ByVal Value As String)
Me.m_BoundColumn = Value
End Set
End Property
End Class
STEP 2: Create a ColumnHeaderCollection object that inherits from
ColumnHeaderCollection and shadows functions which assign and retrieve my
custom DataBoundColumnHeader object
Public Class DataBoundColumnHeaderCollection
Inherits ListView.ColumnHeaderCollection
Public Sub New(ByVal Owner As ListView)
MyBase.New(Owner)
End Sub
Default Public Shadows ReadOnly Property Item(ByVal Index As
Integer) As DataBoundColumnHeader
Get
Return CType(MyBase.Item(Index), DataBoundColumnHeader)
End Get
End Property
Public Shadows Function Add(ByVal Column As DataBoundColumnHeader)
As Integer
Return MyBase.Add(Column)
End Function
Public Shadows Function Add(ByVal Text As String, ByVal width As
Integer, _
ByVal TextAlign As HorizontalAlignment) As DataBoundColumnHeader
Return CType(MyBase.Add(Text, width, TextAlign),
DataBoundColumnHeader)
End Function
'This should be public: but a conversion type error occurs
Private Shadows Sub AddRange(ByVal Values() As
DataBoundColumnHeader)
MyBase.AddRange(Values)
End Sub
End Class
STEP 3: Create a ListView object that inherits from ListView shadowing the
Columns property to accept my ColumnHeaderCollection
Public Class DataBoundListView
Inherits System.Windows.Forms.ListView
Private m_DataBoundColumns As New
DataBoundColumnHeaderCollection(Me)
<Category("Behavior"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)>
_
Public Shadows ReadOnly Property Columns() As
DataBoundColumnHeaderCollection
Get
Return m_DataBoundColumns
End Get
End Property
End Class
THE PROBLEM:
PROBLEM 1: This will not work unless the shadowed function AddRange is
private and not public: The error is a typeconversion error
PROBLEM 2: When I add the DataBoundListViewControl to a form and add some
columns I get the following automatically generated code:
'Notice the System.Windows.Forms.ColumnHeader object
Me.DataBoundListView1.Columns.AddRange(New
System.Windows.Forms.ColumnHeader() {Me.DataBoundColumnHeader9,
Me.DataBoundColumnHeader10})
Me.DataBoundListView1.Location = New System.Drawing.Point(72, 104)
Me.DataBoundListView1.Name = "DataBoundListView1"
Me.DataBoundListView1.TabIndex = 0
Me.DataBoundListView1.View = System.Windows.Forms.View.Details
The automatic code generator creates an array of new ColumnHeader objects
but assigns DataBoundColumnHeader ojects to items in that array. This is a
little confusing. I really prefer it creates an array of
DataBoundColumnHeader objects and then I could make my Private AddRange,
Public.
Thanks in advance,
Demetrio