Struggling with Field validation from a datagridview

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 15-Jul-2006 19:07:44   

Hi, Using V2, Adapter and VB.

I'm trying to validate entries made via a grid and I just don't seem to get it disappointed I've created a partial class of my RegionEntity, and defined some simple validation checks for each column. How can I indicate an error at the UI (on the Grid)?

Imports PMIS.DAL
Imports PMIS.DAL.FactoryClasses
Imports PMIS.DAL.HelperClasses
Imports SD.LLBLGen.Pro.ORMSupportClasses
Namespace PMIS.DAL.EntityClasses
    Partial Public Class RegionEntity
        Protected Overrides Function onvalidateFieldValue(ByVal fieldindex As Integer, ByVal value As Object) As Boolean
            Dim toReturn As Boolean = True
            Select Case CType(fieldindex, RegionFieldIndex)
                Case RegionFieldIndex.RegionCode
                    'Code must not be blank
                    If Len(value) < 3 Then
                        'Indicate the error ????
                        toReturn = False
                    End If
                Case RegionFieldIndex.RegionName
                    'UN Region Name must not be blank
                    toReturn = (Len(value) > 0)
                Case RegionFieldIndex.ComSecRegionName
                    'Must not be blank
                    toReturn = (Len(value) > 0)
            End Select
        End Function

    End Class

End Namespace

If I have to report the error within the UI, how do I pickup the return value (toReturn) from the grid?

Is it significant that parameter onvalidateFieldValue in

        Protected Overrides Function onvalidateFieldValue(ByVal fieldindex As Integer, ByVal value As Object) As Boolean

is being displayed the way it was typed i.e. Intellisense did not complete the text. Does this indicate that I'm missing a reference to what??

Finally, after entering data in a cell, this value is removed when the focus moves to the next cell/field.

I don't think I'm too far off, but I'm really stuck confused any comments would help.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 15-Jul-2006 21:09:41   

Markiemac wrote:

Hi, Using V2, Adapter and VB.

I'm trying to validate entries made via a grid and I just don't seem to get it disappointed I've created a partial class of my RegionEntity, and defined some simple validation checks for each column. How can I indicate an error at the UI (on the Grid)?

Use an ErrorProvider control. You then also use the IDataErrorInfo implementation of the entity. Please consult the manual for how IDataErrorInfo is implemented on entities and how to set field errors and entity errors.

Imports PMIS.DAL
Imports PMIS.DAL.FactoryClasses
Imports PMIS.DAL.HelperClasses
Imports SD.LLBLGen.Pro.ORMSupportClasses
Namespace PMIS.DAL.EntityClasses
    Partial Public Class RegionEntity
        Protected Overrides Function onvalidateFieldValue(ByVal fieldindex As Integer, ByVal value As Object) As Boolean
            Dim toReturn As Boolean = True
            Select Case CType(fieldindex, RegionFieldIndex)
                Case RegionFieldIndex.RegionCode
                    'Code must not be blank
                    If Len(value) < 3 Then
                        'Indicate the error ????
                        toReturn = False
                    End If
                Case RegionFieldIndex.RegionName
                    'UN Region Name must not be blank
                    toReturn = (Len(value) > 0)
                Case RegionFieldIndex.ComSecRegionName
                    'Must not be blank
                    toReturn = (Len(value) > 0)
            End Select
        End Function

    End Class

End Namespace

If I have to report the error within the UI, how do I pickup the return value (toReturn) from the grid?

You don't, you set the error message for the field, the ErrorProvider control on the form will make sure the error is displayed.

Is it significant that parameter onvalidateFieldValue in

        Protected Overrides Function onvalidateFieldValue(ByVal fieldindex As Integer, ByVal value As Object) As Boolean

is being displayed the way it was typed i.e. Intellisense did not complete the text. Does this indicate that I'm missing a reference to what??

The method looks fine. Please see 'IDataErrorInfo implementation' in Using the entity classes. Also see Validation per field or per entity.

Finally, after entering data in a cell, this value is removed when the focus moves to the next cell/field.

that means the value isn't accepted, which is the result that validation fails.

Frans Bouma | Lead developer LLBLGen Pro
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 16-Jul-2006 11:55:58   

Frans,

I'm stunned at your quick response, thought I was the only one working so late and apologies for the naive questions (still climbing the slope).

I'll be looking at this later on, so please don't close the thread just yet. There is quite a bit in the docs but not many validation threads for V2 so other naive .Net developers like myself might find my feedback useful.

Thanks