andy0809

combobox still empty

Discussion created by andy0809 on Jul 5, 2010
Latest reply on Jul 6, 2010 by thaviti
Hi All
I have 2 combo boxes in userform, the 1st named cboSatuanLahan and the 2nd named cboKabupaten. I wrote the code on the userform_initialize to list the value of each field. cboSatuanLahan will list the value of field Land_Unit, and cboKabupaten will list the value of field KABUPATEN. But why only cboSatuanLahan that lists the value of Land_Unit (has redudance value in its cbo), whereas cboKabupaten is empty. Any suggestion to solve my problems?
Thanks

Private Sub UserForm_Initialize()
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFeatLayer As IFeatureLayer
Dim pFeatClass As IFeatureClass
Dim pFields As IFields
Dim pField As IField
Dim i As Integer

Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
Set pFeatLayer = pMap.Layer(0)
Set pFeatClass = pFeatLayer.FeatureClass
Set pFields = pFeatClass.fields

For i = 0 To pFields.FieldCount - 1
    cboSatuanLahan.AddItem pFields.field(i).Name
    cboKabupaten.AddItem pFields.field(i).Name
Next

Dim pLayer As ILayer
Set pLayer = pMap.Layer(0)
Set pFeatLayer = pLayer
Dim pFeature As IFeature
Dim pFeatCursor As IFeatureCursor
Dim pQueryFilter As IQueryFilter
Set pQueryFilter = New queryFilter
pQueryFilter.SubFields = "Land_Unit"
Set pFeatCursor = pFeatLayer.Search(pQueryFilter, True)
Set pFeature = pFeatCursor.NextFeature

'Cek redudansi di cboSatuanLahan
Dim j As Integer
Dim cDuplicate As Boolean
cDuplicate = False

cboSatuanLahan.Clear
Do While Not pFeature Is Nothing
For j = 0 To cboSatuanLahan.ListCount - 1
    cDuplicate = False
    If cboSatuanLahan.List(j) = pFeature.Value(pFeature.fields.FindField("Land_Unit")) Then
        cDuplicate = True
    End If
Next j

    If cDuplicate = False Then
        cboSatuanLahan.AddItem pFeature.Value(pFeature.fields.FindField("Land_Unit"))
    End If
Set pFeature = pFeatCursor.NextFeature

Loop

''Cek redudansi di cboKabupaten
Dim m As Integer
Dim kDuplicate As Boolean
kDuplicate = False

cboKabupaten.Clear
Do While Not pFeature Is Nothing

For m = 0 To cboKabupaten.ListCount - 1
    kDuplicate = False
    If cboKabupaten.List(m) = pFeature.Value(pFeature.fields.FindField("KABUPATEN")) Then
        kDuplicate = True
    End If
Next m

    If kDuplicate = False Then
        cboKabupaten.AddItem pFeature.Value(pFeature.fields.FindField("KABUPATEN"))
    End If
Set pFeature = pFeatCursor.NextFeature
Loop

Set pFeatCursor = Nothing
Set pFeature = Nothing
Set pFeatLayer = Nothing
Set pLayer = Nothing
Set pMap = Nothing
Set pMxDoc = Nothing
End Sub

Outcomes