Help with binding gridview to an object containing a collection of objects
This is a followup question to one I posted a couple of weeks ago. I have an Object (bootset), which I want to bind to my gridview. It contains 2 sets of chilld objects, which i must access. Here is the Boot/Bootset classes:
Code:
Option Explicit On
Public Class Boot
'Contains a head and shell
#Region "Private Variables"
Private _oHeadSet As New HeadSet
Private _oShellSet As New ShellSet
Private _iBootID As Integer
#End Region
#Region "Constructors"
Public Sub New()
_oHeadSet = New WQS_BusinessEntity.HeadSet
Dim oHead As New Head
_oHeadSet.Add(oHead)
_oShellSet = New WQS_BusinessEntity.ShellSet
Dim oShell As New Shell
_oShellSet.Add(oShell)
End Sub
Public Sub New(ByVal oHeadSet As HeadSet, ByVal oShellSet As ShellSet, ByVal iBootID As Integer, ByVal iBootTypeID As Integer, ByVal iVesselID As Integer)
_oHeadSet = New WQS_BusinessEntity.HeadSet
_oShellSet = New WQS_BusinessEntity.ShellSet
Dim oHead As New Head
Dim oShell As New Shell
_oHeadSet.Add(oHead)
_oShellSet.Add(oShell)
_iBootID = iBootID
End Sub
#End Region
#Region "Public Properties"
Public Property oHeadSet() As WQS_BusinessEntity.HeadSet
Get
Return _oHeadSet
End Get
Set(ByVal oValue As HeadSet)
_oHeadSet = oValue
End Set
End Property
Public Property oShellSet() As WQS_BusinessEntity.ShellSet
Get
Return _oShellSet
End Get
Set(ByVal oValue As ShellSet)
_oShellSet = oValue
End Set
End Property
Public Property iBootID() As Integer
Get
Return _iBootID
End Get
Set(ByVal iValue As Integer)
_iBootID = iValue
End Set
End Property
#End Region
End Class
Public Class BootSet
Inherits Collections.ArrayList
Public Shadows Function Add(ByVal oValue As Boot) As Integer
If Not oValue Is Nothing Then
MyBase.Add(oValue)
End If
End Function
Default Public Shadows Property Item(ByVal iIndex As Integer) As Boot
Get
Return CType(MyBase.Item(iIndex), Boot)
End Get
Set(ByVal Value As Boot)
MyBase.Item(iIndex) = Value
End Set
End Property
End Class
And the Head/HeadSet Classes:
Code:
Option Explicit On
Public Class Head
Inherits WQS_BusinessEntity.HeadSet
#Region "Private Variables"
Private _iHeadID As Integer
#End Region
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal iHeadID As Integer)
_iHeadID = iHeadID
End Sub
#End Region
#Region "Public Properties"
Public Property iHeadID() As Integer
Get
Return _iHeadID
End Get
Set(ByVal iValue As Integer)
_iHeadID = iValue
End Set
End Property
#End Region
End Class
Public Class HeadSet
Inherits Collections.ArrayList
Public Shadows Function Add(ByVal oValue As Head) As Integer
If Not oValue Is Nothing Then
MyBase.Add(oValue)
End If
End Function
Default Public Shadows Property Item(ByVal iIndex As Integer) As Head
Get
Return CType(MyBase.Item(iIndex), Head)
End Get
Set(ByVal Value As Head)
MyBase.Item(iIndex) = Value
End Set
End Property
End Class
And my Shell/ShellSet:
Code:
Option Explicit On
Public Class Shell
Inherits WQS_BusinessEntity.ShellSet
#Region "Private Variables"
Private _iShellID As Integer
#End Region
#Region "Constructors"
Public Sub New()
End Sub
Public Sub New(ByVal iShellID As Integer)
_iShellID = iShellID
End Sub
#End Region
#Region "Public Properties"
Public Property iShellID() As Integer
Get
Return _iShellID
End Get
Set(ByVal iValue As Integer)
_iShellID = iValue
End Set
End Property
#End Region
End Class
Public Class ShellSet
Inherits Collections.ArrayList
Public Shadows Function Add(ByVal oValue As Shell) As Integer
If Not oValue Is Nothing Then
MyBase.Add(oValue)
End If
End Function
Default Public Shadows Property Item(ByVal iIndex As Integer) As Shell
Get
Return CType(MyBase.Item(iIndex), Shell)
End Get
Set(ByVal Value As Shell)
MyBase.Item(iIndex) = Value
End Set
End Property
End Class
Notice that this Bootset Object contains one to many boots, each of which contains a headset and a shellset. a headset/shellset can contain one or more heads/shells. I need to Access (display) the properties in the contained obects, and do so in my gridview. Here is my code from my gridview, but as you can see i just dont know how to do what Im trying to accomplish.
Re: Help with binding gridview to an object containing a collection of objects
asp.net...I am moving this thread there...
************************************
seems as if you're looking for a hiearchichal control, and thait is not natively gridview, but dataGrid. Yoou could extend the first, or use the second
here some samples that could help you (do not expect them to be perfect, you will have to adjust them to your needs): http://www.codeproject.com/KB/custom...tgridview.aspx http://www.codeproject.com/KB/webfor...rDataGrid.aspx
Last edited by Cimperiali; February 10th, 2010 at 05:31 PM.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
Re: Help with binding gridview to an object containing a collection of objects
Actually, that is not what I am trying to do. It does help me however as I am building an extended gridview myself, which does what those articles illustrate.
With my current problem, I do not have child rows - just child objects. the Bootset is the parent object, and it contains a headset,a bootset, and a bootid. In my actual application there are other properties, but I simplified the problem for clarity. I want to display one row for each boot - which would also display the headid and the shellid for that boot.
I have attached a zipped solution, which may make things clearer....it also contains code which is my efforts to solve the problem (the GetHeadID and GetShellID functions)
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.