Problems using my Validator Class

Posts   
 
    
Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 12-Sep-2007 00:10:22   

Hi, Using V2.0, Adapter, VB

Am experimenting with ValidatorClasses and have some problems.

My RegionEntity DataGridView has 2 columns, populated with via calls to a Manager Class to get the collection. I'm trying to use ValidateEntity to validate row input in the grid, before leaving the row.

I've overriden ValidateEntity in my Validator class as follows:

Imports ARTEMIS.DAL.EntityClasses
Imports SD.LLBLGen.Pro.ORMSupportClasses
Namespace ValidatorClasses
    Public NotInheritable Class ISORegionValidator
        Inherits ValidatorBase

        Public Overrides Sub ValidateEntity(ByVal involvedEntity As SD.LLBLGen.Pro.ORMSupportClasses.IEntityCore)

            Dim toValidate As ISORegionEntity = CType(involvedEntity, ISORegionEntity)
            If toValidate.ISORegionID = 10 Then
                Throw New ORMEntityValidationException("ISORegion ID invalid", toValidate)
            End If

            MyBase.ValidateEntity(involvedEntity)
        End Sub
    End Class
End Namespace

Have also set the entity's validator via a partial class as follows:

Imports SD.LLBLGen.Pro.ORMSupportClasses
Namespace ARTEMIS.DAL.EntityClasses
    Partial Public Class ISORegionEntity
        Protected Overrides Function createValidator() As IValidator
            Return New ValidatorClasses.ISORegionValidator()
        End Function
    End Class
End Namespace

I want to validate the row before leaving it, but I'm having difficulty in working out how to do so with the existing entity instance. If I use the following:

        Dim myEntity As New ISORegionEntity
        myEntity.ValidateEntity()

Then run the app and enter 10 for ISORegionID, ValidateEntity is called but toValidate.ISORegionID is of course 0.

How do I do this? confused Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Sep-2007 11:15:28   

Find the appropriate DataGridView event to handle (eg. RowLeave) Then grab the entity from the row DataBoundItem and then call ValidateEntity.

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 12-Sep-2007 14:39:26   

Hi Walaa,

I had the appropriate grid leaving event sorted, but the DataboundItem was what I was after and in an MS DataGridView the following code works fine.

Dim myEntity As ISORegionEntity = CType(Me.DataGridView1.Rows(e.RowIndex).DataBoundItem, ISORegionEntity)
myEntity.ValidateEntity()

However I'm using DevExpress XtraGrid and I haven't successfully found the equivalent of Me.DataGridView1.Rows(e.RowIndex).DataBoundItem in order to get the entity from the row.

I know that XtraGrid has the GetRow function that returns an object representing a specific row but when I use the following:

RowNo = CInt(myView.FocusedRowHandle)
Dim myEntity As ISORegionEntity = CType(Me.GridView1.GetDataRow(RowNo), ISORegionEntity)
myEntity.ValidateEntity()

Me.GridView1.GetDataRow(RowNo) gives me a type conversion error i.e. System.Data.DataRow cannot be converted to etc...ISORegionEntity

It should be possible to avoid loading up the entity manually as per:

Dim myEntity As New ISORegionEntity
myEntity.RegionID = CShort(myView.GetFocusedRowCellValue("RegionID"))
myEntity.RegionName = CStr(myView.GetFocusedRowCellValue("RegionName"))
myEntity.ValidateEntity()

Can any DevExpress XtraGrid users help out here? Thanks

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 12-Sep-2007 16:05:45   

I'm not familier with the DevExpress XtraGrid. So I don't know how to better use the GetDataRow() or any alternative method. What's the retunrType of GetDataRow()?

But anyway it seems as a DevExpress issue, and not related to LLBLGen Pro. Have you contacted them about it?

I know for sure that we have many customers using the XtraGrid, so there should be a way to do this.

Markiemac
User
Posts: 132
Joined: 25-Apr-2006
# Posted on: 12-Sep-2007 16:48:25   

Walaa wrote:

I'm not familier with the DevExpress XtraGrid. So I don't know how to better use the GetDataRow() or any alternative method. What's the returnType of GetDataRow()?

Whoops!! Should have been 'GetRow' (An object representing a specific row) not GetDataRow. Closed.

Thanks smile