locked
Detect when DataColumn Error is set in Typed DataSet RRS feed

  • Question

  • I have a typed dataset that I want to detect whenever a data column error is set (perhaps subscribing to an event).  Currently, I don't know of a way to do this because you can't override the DataRow.SetColumnError() method.  I have created a Partial Class for my typed dataset which extends the typed dataset.  The only way I can think of is to create an overload of the DataRow.SetColumnError() method, but would prefer to override.  Any ideas?

    Please note my datacolumns and other methods of the typed dataset are not pasted here, but they do exist in the partial class the typed dataset auto-generated code.

    Partial Public Class MyTypedDataSet
        Partial Public Class MyTypedDataTable
    
            Public Event ColumnErrorChanged(sender As MyTypedDataTable, e As DataColumnErrorEventArgs)
    
            Public Overridable Sub OnColumnErrorChanged(ByVal e As DataColumnErrorEventArgs)
                RaiseEvent ColumnErrorChanged(Me, e)
            End Sub
    
        End Class
    
        Partial Public Class MyTypedDataRow
    
            Public Sub SetColumnError(ByVal dataColumn As DataColumn, ByVal [error] As String)
                MyBase.SetColumnError(dataColumn, [error])
                Dim e As New DataColumnErrorEventArgs(dataColumn, Me, [error])
                Me.MyTypedDataTable.OnColumnErrorChanged(e)
            End Sub
        End Class
    End Class
    
    Public Class DataColumnErrorEventArgs
        Inherits EventArgs
    
        Private _column As DataColumn
        Private _dataRow As DataRow
        Private _error As String
    
        Public ReadOnly Property Column As DataColumn
            Get
                Return Me._column
            End Get
        End Property
        Public ReadOnly Property DataRow As DataRow
            Get
                Return Me._dataRow
            End Get
        End Property
        Public ReadOnly Property [Error] As String
            Get
                Return Me._error
            End Get
        End Property
    
        Public Sub New(ByRef column As DataColumn, ByRef dataRow As DataRow, ByVal [error] As String)
            MyBase.New()
            Me._column = column
            Me._dataRow = dataRow
            Me._error = [error]
        End Sub
    End Class



    Ryan

    Tuesday, February 2, 2016 1:59 AM

Answers

  • Do you mean that you want to raise an event whenever an error happens on a DataColumn? the SetColumn is just for the purpose of setting custom error messages on that Column.

    Fouad Roumieh

    Tuesday, February 2, 2016 6:27 AM