[Visual Basic 6.0]The following code demonstrates simple custom validation that requires the value of the field to be divisible by two.
To use this example:
- Paste this code into a class module in a ActiveX dll Visual Basic project.
- Compile the project to create the dll.
- Use the IClassSchemaEdit interface to put the GUID of this class extension in the EXTCLSID property for the object class or feature class that you want to associate this class extension with.
- To test this class extension, add the feature class or object class to ArcMap, select some objects and use the Validate Selection command and if the rule is violated, those objects will be returned as invalid.
Implements IObjectClassExtension Implements IObjectClassValidationPrivate m_pClassHelper As IClassHelper Private m_myValueIndex As Long Private Const MYVALUE_FIELDNAME As String = "MyValue"Private Sub IClassExtension_Init(ByVal pClassHelper As esriGeoDatabase.IClassHelper, ByVal pExtensionProperties As esriSystem.IPropertySet) Set m_pClassHelper = pClassHelper Dim pClass As IClassSet pClass = m_pClassHelper.Class m_myValueIndex = pClass.FindField(MYVALUE_FIELDNAME) End SubPrivate Sub IClassExtension_Shutdown() ‘Release Helper here Set m_pClassHelper = Nothing End SubPrivate Function IObjectClassValidation_ValidateField(ByVal Row As esriGeoDatabase.IRow, ByVal FIELDNAME As String) As String Dim errStr As String errStr = ""If FIELDNAME = MYVALUE_FIELDNAME Then Dim myValue As Long myValue = Row.value(m_myValueIndex) Dim modValue As Long modValue = myValue Mod 2If modValue > 0 Then errStr = "Field value is not divisible by 2." End IfEnd If IObjectClassValidation_ValidateField = errStr End FunctionPrivate Function IObjectClassValidation_ValidateRow(ByVal Row As esriGeoDatabase.IRow) As String IObjectClassValidation_ValidateRow = _ IObjectClassValidation_ValidateField(Row, MYVALUE_FIELDNAME) End Function
[Visual Basic .NET, C#, C++]
No example is available for Visual Basic .NET, C#, or C++. To view a Visual Basic 6.0 example, click the Language Filter button
in the upper-left corner of the page.