The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
In an overridden datagrid, I am overriding the DataSource property, so that on changing the source in design mode, the GridBoundColumns will automatically populate.
The following code works fine
Public Overrides Property DataSource() As Object
Get
Return _datasource
End Get
Set(ByVal Value As Object)
_datasource = Value
MyBase.DataSource = Value
If Me.DesignMode AndAlso Not Value Is Nothing Then
If Me.GridBoundColumns.Count = 0 Then
If Value.GetType.IsSubclassOf(GetType(DataTable)) Then
For Each dc As DataColumn In CType(Value, DataTable).Columns
Dim gbc As New GridBoundColumn
With gbc
.MappingName = dc.ColumnName
.HeaderText = dc.ColumnName
.ReadOnly = dc.ReadOnly
.StyleInfo.CellValueType = dc.DataType
.Owner = Me.Binder
If dc.DataType Is GetType(Date) Then
.StyleInfo.CellType = "MonthCalendar"
ElseIf dc.DataType Is GetType(Boolean) Then
.StyleInfo.CellType = "CheckBox"
.StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Center
Else
.StyleInfo.CellType = "TextBox"
End If
If dc.DataType Is GetType(Decimal) Or dc.DataType.GetType Is GetType(Double) Then
.StyleInfo.Format = "#,##0.00;-#,##0.00;-"
.StyleInfo.HorizontalAlignment = GridHorizontalAlignment.Right
End If
End With
Me.GridBoundColumns.Add(gbc)
Next
End If
End If
End If
End Set
End Property
However, I would like to be able to automatically set the "name" of the column, based on the MappingName, i.e. "col" & MappingName at the time that the column is added to the collection. How would I go about doing this?
Many thanks in advance
Jeremy
ADAdministrator Syncfusion Team April 20, 2003 06:15 PM UTC
I am not sure I fully understand what you want.
There is a GridDataBoundGrid.GridBoundColumns.CollectionChanged event you can try to catch to see if that will allow you to do what you want.
UNUnknown Syncfusion Team April 21, 2003 10:40 AM UTC
Clay
I attach my attempt at overriding the grid.
In the overridden Set DataSource property I have placed a comment to you better explaining what I'm trying to do.
Many thanks
Jeremy