T
Terry Holland
I want to create a datagrid with different "row types".
To illustrate my point I'll describe a simplified version of what I want.
I have a list of stock with the following fields:
StockCode, Description, Price, NumberInStock.
Stock is grouped into stock groups. What I would like to do is display the
stock in a datagrid so that the stock appears under the stock group that it
belongs to.
ie
Tube Materials
10001, Steel Tube (1m), £10.00, 1000
10002, Steel Tube (2m), £19.00, 1500
Board Materials
20001, Standard Board (4m), £15, 3000
20002, Other Board, £10,2000
etc...
Is there any way that I can display my grid with the stock group headings in
their own row in the grid followed by the stock in that group.
The code that I have supplied is a very simplified version of what I am
using at the moment (I actually use custom datgrid columns that get created
at runtime). When this code runs, you will see that the stock group data is
displayed as an extra column in the grid. I would like it to display as a
seperate row, formatted differently to stock rows with a single column
spanning entire grid.
Id appreciate any examples of how I might achieve this
Terry Holland
'=================================================
'STOCK CLASS
'=================================================
Public Class clsStock
Private m_strStockCode As String
Private m_strName As String
Private m_sglPrice As Single
Private m_intRemaining As Int16
Private m_strStockGroup As String
Private Sub New()
End Sub
Public Sub New(ByVal strStockCode As String, ByVal strName As String,
ByVal sglPrice As Single, ByVal intRemaining As Integer, ByVal strStockGroup
As String)
StockCode = strStockCode
Name = strName
Price = sglPrice
Remaining = intRemaining
m_strStockGroup = strStockGroup
End Sub
Public Property StockCode() As String
Get
Return m_strStockCode
End Get
Set(ByVal Value As String)
m_strStockCode = Value
End Set
End Property
Public Property Name() As String
Get
Return m_strName
End Get
Set(ByVal Value As String)
m_strName = Value
End Set
End Property
Public Property Price() As Single
Get
Return m_sglPrice
End Get
Set(ByVal Value As Single)
m_sglPrice = Value
End Set
End Property
Public Property Remaining() As Int16
Get
Return m_intRemaining
End Get
Set(ByVal Value As Int16)
m_intRemaining = Value
End Set
End Property
Public Property StockGroup() As String
Get
Return m_strStockGroup
End Get
Set(ByVal Value As String)
m_strStockCode = Value
End Set
End Property
End Class
'=================================================
'STOCKLIST CLASS
'=================================================
Public Class clsStockList
Inherits CollectionBase
Public Sub New()
Dim s As clsStock
s = New clsStock("10001", "Steel Tube (1m)", 10, 1000, "TUBE
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("10002", "Steel Tube (2m)", 19, 2000, "TUBE
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("20001", "Standard Board", 10, 3000, "BOARD
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("20002", "Other Board", 13, 1000, "BOARD
MATERIALS")
MyBase.List.Add(s)
End Sub
End Class
'=================================================
'PAGE CODE
'=================================================
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
GetData()
End Sub
Private Sub GetData()
Dim sl As New clsStockList
DataGrid1.DataSource = sl
DataGrid1.DataBind()
End Sub
End Class
To illustrate my point I'll describe a simplified version of what I want.
I have a list of stock with the following fields:
StockCode, Description, Price, NumberInStock.
Stock is grouped into stock groups. What I would like to do is display the
stock in a datagrid so that the stock appears under the stock group that it
belongs to.
ie
Tube Materials
10001, Steel Tube (1m), £10.00, 1000
10002, Steel Tube (2m), £19.00, 1500
Board Materials
20001, Standard Board (4m), £15, 3000
20002, Other Board, £10,2000
etc...
Is there any way that I can display my grid with the stock group headings in
their own row in the grid followed by the stock in that group.
The code that I have supplied is a very simplified version of what I am
using at the moment (I actually use custom datgrid columns that get created
at runtime). When this code runs, you will see that the stock group data is
displayed as an extra column in the grid. I would like it to display as a
seperate row, formatted differently to stock rows with a single column
spanning entire grid.
Id appreciate any examples of how I might achieve this
Terry Holland
'=================================================
'STOCK CLASS
'=================================================
Public Class clsStock
Private m_strStockCode As String
Private m_strName As String
Private m_sglPrice As Single
Private m_intRemaining As Int16
Private m_strStockGroup As String
Private Sub New()
End Sub
Public Sub New(ByVal strStockCode As String, ByVal strName As String,
ByVal sglPrice As Single, ByVal intRemaining As Integer, ByVal strStockGroup
As String)
StockCode = strStockCode
Name = strName
Price = sglPrice
Remaining = intRemaining
m_strStockGroup = strStockGroup
End Sub
Public Property StockCode() As String
Get
Return m_strStockCode
End Get
Set(ByVal Value As String)
m_strStockCode = Value
End Set
End Property
Public Property Name() As String
Get
Return m_strName
End Get
Set(ByVal Value As String)
m_strName = Value
End Set
End Property
Public Property Price() As Single
Get
Return m_sglPrice
End Get
Set(ByVal Value As Single)
m_sglPrice = Value
End Set
End Property
Public Property Remaining() As Int16
Get
Return m_intRemaining
End Get
Set(ByVal Value As Int16)
m_intRemaining = Value
End Set
End Property
Public Property StockGroup() As String
Get
Return m_strStockGroup
End Get
Set(ByVal Value As String)
m_strStockCode = Value
End Set
End Property
End Class
'=================================================
'STOCKLIST CLASS
'=================================================
Public Class clsStockList
Inherits CollectionBase
Public Sub New()
Dim s As clsStock
s = New clsStock("10001", "Steel Tube (1m)", 10, 1000, "TUBE
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("10002", "Steel Tube (2m)", 19, 2000, "TUBE
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("20001", "Standard Board", 10, 3000, "BOARD
MATERIALS")
MyBase.List.Add(s)
s = New clsStock("20002", "Other Board", 13, 1000, "BOARD
MATERIALS")
MyBase.List.Add(s)
End Sub
End Class
'=================================================
'PAGE CODE
'=================================================
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
GetData()
End Sub
Private Sub GetData()
Dim sl As New clsStockList
DataGrid1.DataSource = sl
DataGrid1.DataBind()
End Sub
End Class