T
Terry Holland
I am trying to write a user control that is essentially a DataGrid with some
custom functionality. My grid is to be bound to a custom collection.
I have created an interface called IListData. Part of this interface is a
collection of DataGridColumn objects. I have code in my control to add a
bound column for each column I have in my collection of columns shown below.
What I would like to do is decide which type of column to use for each of my
bound columns - ie I might want to have a checkbox in one of my columns - or
I might need a dropdown list in another columns. Im having difficulty with
showing bound columns as anything other than text ie checkbox, dropdown box
etc
'################ 'Add columns to grid #########################
For Each objDataGridColumn As clsDataGridColumn In
ListData.DataGridColumns
objBoundColumn = New BoundColumn
'intWidth = objDataGridColumn.Width
With objBoundColumn
.DataField = objDataGridColumn.DataField
.HeaderText = objDataGridColumn.Caption
.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
.ItemStyle.HorizontalAlign = objDataGridColumn.Align
If objDataGridColumn.Width = 0 Then
.Visible = False
Else
.HeaderStyle.Width =
Unit.Percentage(objDataGridColumn.Width)
End If
End With
DataGrid1.Columns.Add(objBoundColumn)
Next
'################ End #########################
'################ clsDataGridColumn #########################
Public Enum enuColumnType
Label
Textbox
Dropdown
Checkbox
End Enum
Public Enum enuAlign
Left
Right
Centre
End Enum
<Serializable()> _
Public Class clsDataGridColumn
Private m_strDataField As String
Private m_strCaption As String
Private m_ColumnType As enuColumnType
Private m_Align As HorizontalAlign
Private m_intWidth As Integer
Private Sub New()
End Sub
Private Sub New(ByVal strDataField As String, ByVal strCaption As
String, ByVal ColumnType As enuColumnType, ByVal Align As enuAlign, ByVal
intWidth As Integer)
m_strDataField = strDataField
m_strCaption = strCaption
m_ColumnType = ColumnType
m_Align = GetHorizontalAlign(Align)
m_intWidth = intWidth
End Sub
Public Shared Function NewObject(ByVal strDataField As String, ByVal
strCaption As String, ByVal ColumnType As enuColumnType, ByVal Align As
enuAlign, ByVal intWidth As Integer) As clsDataGridColumn
Return New clsDataGridColumn(strDataField, strCaption, ColumnType,
Align, intWidth)
End Function
Private Function GetHorizontalAlign(ByVal Align As enuAlign) As
HorizontalAlign
Select Case Align
Case enuAlign.Left
Return HorizontalAlign.Left
Case enuAlign.Centre
Return HorizontalAlign.Center
Case enuAlign.Right
Return HorizontalAlign.Right
Case Else
Return HorizontalAlign.NotSet
End Select
End Function
Public ReadOnly Property DataField() As String
Get
Return m_strDataField
End Get
End Property
Public ReadOnly Property ColumnType() As enuColumnType
Get
Return m_ColumnType
End Get
End Property
Public ReadOnly Property Width() As Integer
Get
Return m_intWidth
End Get
End Property
Public ReadOnly Property Caption() As String
Get
Return m_strCaption
End Get
End Property
Public ReadOnly Property Align() As HorizontalAlign
Get
Return m_Align
End Get
End Property
'################ End #########################
custom functionality. My grid is to be bound to a custom collection.
I have created an interface called IListData. Part of this interface is a
collection of DataGridColumn objects. I have code in my control to add a
bound column for each column I have in my collection of columns shown below.
What I would like to do is decide which type of column to use for each of my
bound columns - ie I might want to have a checkbox in one of my columns - or
I might need a dropdown list in another columns. Im having difficulty with
showing bound columns as anything other than text ie checkbox, dropdown box
etc
'################ 'Add columns to grid #########################
For Each objDataGridColumn As clsDataGridColumn In
ListData.DataGridColumns
objBoundColumn = New BoundColumn
'intWidth = objDataGridColumn.Width
With objBoundColumn
.DataField = objDataGridColumn.DataField
.HeaderText = objDataGridColumn.Caption
.HeaderStyle.HorizontalAlign = HorizontalAlign.Center
.ItemStyle.HorizontalAlign = objDataGridColumn.Align
If objDataGridColumn.Width = 0 Then
.Visible = False
Else
.HeaderStyle.Width =
Unit.Percentage(objDataGridColumn.Width)
End If
End With
DataGrid1.Columns.Add(objBoundColumn)
Next
'################ End #########################
'################ clsDataGridColumn #########################
Public Enum enuColumnType
Label
Textbox
Dropdown
Checkbox
End Enum
Public Enum enuAlign
Left
Right
Centre
End Enum
<Serializable()> _
Public Class clsDataGridColumn
Private m_strDataField As String
Private m_strCaption As String
Private m_ColumnType As enuColumnType
Private m_Align As HorizontalAlign
Private m_intWidth As Integer
Private Sub New()
End Sub
Private Sub New(ByVal strDataField As String, ByVal strCaption As
String, ByVal ColumnType As enuColumnType, ByVal Align As enuAlign, ByVal
intWidth As Integer)
m_strDataField = strDataField
m_strCaption = strCaption
m_ColumnType = ColumnType
m_Align = GetHorizontalAlign(Align)
m_intWidth = intWidth
End Sub
Public Shared Function NewObject(ByVal strDataField As String, ByVal
strCaption As String, ByVal ColumnType As enuColumnType, ByVal Align As
enuAlign, ByVal intWidth As Integer) As clsDataGridColumn
Return New clsDataGridColumn(strDataField, strCaption, ColumnType,
Align, intWidth)
End Function
Private Function GetHorizontalAlign(ByVal Align As enuAlign) As
HorizontalAlign
Select Case Align
Case enuAlign.Left
Return HorizontalAlign.Left
Case enuAlign.Centre
Return HorizontalAlign.Center
Case enuAlign.Right
Return HorizontalAlign.Right
Case Else
Return HorizontalAlign.NotSet
End Select
End Function
Public ReadOnly Property DataField() As String
Get
Return m_strDataField
End Get
End Property
Public ReadOnly Property ColumnType() As enuColumnType
Get
Return m_ColumnType
End Get
End Property
Public ReadOnly Property Width() As Integer
Get
Return m_intWidth
End Get
End Property
Public ReadOnly Property Caption() As String
Get
Return m_strCaption
End Get
End Property
Public ReadOnly Property Align() As HorizontalAlign
Get
Return m_Align
End Get
End Property
'################ End #########################