' Copyright 2008 ESRI
'
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
'
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
'
' See use restrictions at <your ArcGIS install location>/developerkit/userestrictions.txt.
'
Option Explicit
Private m_pWork As IWorkspaceDomains2
Private Sub cmbDomains_Click()
PopulateGrid
End Sub
Private Sub cmdCancel_Click()
Set m_pWork = Nothing
Me.Hide
End Sub
Private Sub cmdOK_Click()
Me.Hide
End Sub
Private Sub Form_Load()
On Error GoTo ErrHandler:
If m_pWork Is Nothing Then Exit Sub
Dim pEnum As IEnumDomain, pDomain As IDomain
Set pEnum = m_pWork.Domains
pEnum.Reset
cmbDomains.Clear
Set pDomain = pEnum.Next
Do While Not pDomain Is Nothing
If TypeOf pDomain Is ICodedValueDomain Then
cmbDomains.AddItem pDomain.Name
End If
Set pDomain = pEnum.Next
Loop
cmbDomains.ListIndex = 0
optSortType(0).Value = True
optSortItem(1).Value = True
Exit Sub
ErrHandler:
MsgBox "Form_Load - " & Err.Description
End Sub
Property Set Workspace(RHS As IWorkspace)
Set m_pWork = RHS
End Property
Property Get Workspace() As IWorkspace
Set Workspace = m_pWork
End Property
Private Sub Form_Terminate()
Set m_pWork = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set m_pWork = Nothing
End Sub
Private Sub optSortItem_Click(Index As Integer)
SortGrid
End Sub
Private Sub optSortType_Click(Index As Integer)
SortGrid
End Sub
Private Sub PopulateGrid()
On Error GoTo ErrHandler:
'Routine for populating the Grid based on the selected domain
grdDomain.Clear
grdDomain.Rows = 1
grdDomain.ColWidth(0) = grdDomain.Width / 3
grdDomain.ColWidth(1) = grdDomain.Width / 1.5
grdDomain.Col = 0
grdDomain.Row = 0
grdDomain.Text = "Code"
grdDomain.Col = 1
grdDomain.Text = "Description"
grdDomain.ColAlignment(0) = 1
grdDomain.ColAlignment(1) = 1
'Get the domain
Dim pCoded As ICodedValueDomain, lLoop As Long
Set pCoded = m_pWork.DomainByName(cmbDomains.Text)
If pCoded Is Nothing Then
MsgBox "Could not find domain, something is wrong in PopulateGrid routine!!"
Exit Sub
End If
'Populate the grid
For lLoop = 0 To pCoded.CodeCount - 1
grdDomain.AddItem pCoded.Value(lLoop) & Chr(9) & pCoded.Name(lLoop)
Next lLoop
'Sort the Domain based on the current settings
SortGrid
Exit Sub
ErrHandler:
MsgBox "frmDomainSort_PopulateGrid - " & Err.Description
End Sub
Private Sub SortGrid()
'Routine for sorting the domain values in the grid based on the option settings
On Error GoTo ErrHandler:
grdDomain.Row = 1
grdDomain.RowSel = 1
If optSortItem(0).Value Then 'Code sort
grdDomain.Col = 0
grdDomain.ColSel = 0
Else 'Description sort
grdDomain.Col = 1
grdDomain.ColSel = 1
End If
If optSortType(0).Value Then 'Ascending sort
grdDomain.Sort = 1
Else 'Descending sort
grdDomain.Sort = 2
End If
Exit Sub
ErrHandler:
MsgBox "SortGrid - " & Err.Description
End Sub