We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Overriding GridDataBound

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

2 Replies

AD Administrator 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.

UN Unknown 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

Live Chat Icon For mobile
Up arrow icon