Re: Dynamically create datagrid columns



Hi Terry,

Bound column is not for containing some other controls, such as checkbox,
dropdownlist, and so on. You should use TemplateColumn for your purpose.


HTH


"Terry Holland" <terryeholland@xxxxxxxxxxxxxxxx> wrote in message
news:u5WweGqwFHA.720@xxxxxxxxxxxxxxxxxxxxxxx
>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
> #########################
>
>


.



Relevant Pages

  • Dynamically create datagrid columns
    ... Private m_strDataField As String ... String, ByVal ColumnType As enuColumnType, ByVal Align As enuAlign, ByVal ... Public ReadOnly Property DataField() As String ...
    (microsoft.public.dotnet.framework.aspnet.datagridcontrol)
  • Re: Custom Windows Authentication Principal?
    ... > Private m_RolesAs String ... > Public ReadOnly Property UserName() As String ... > Public Sub WindowsAuthentication_OnAuthenticate(ByVal sender As Object, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: How do I use this Class I made?
    ... Private Sub btnFrown_Click(ByVal sender As System.Object, ... Private s As String = "J" ... Public ReadOnly Property normal() As String ... Public ReadOnly Property frown() As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Custom Windows Authentication Principal?
    ... Did you consider inheriting from WindowsIdentity to add ... > Private m_RolesAs String ... > Public ReadOnly Property UserName() As String ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • OOP Inheritance
    ... The Employees have EmployeeDeductions. ... Public Property CompanyIDAs String ... Public ReadOnly Property Employees() As ArrayList ... Public Sub New(ByVal DeductionID As String) ...
    (microsoft.public.dotnet.languages.vb)