vb.net return all field values

1117
5
02-03-2011 12:17 PM
JohnMcCrae1
New Contributor
I am trying to find a simple solution for iterating through all the values in a field not only those that are unique. I have come across examples relating to this topic however they all seem to use something along the lines of :

        pEnumVar = pData.UniqueValues
        value = pEnumVar.MoveNext

        For i = 0 To pData.UniqueValueCount - 1
            ComboBox1.Items.Add(CStr(pEnumVar.Current)) '<--- this should add the values to your cmbLot Control
            value = pEnumVar.MoveNext
        Next 


or

    
 pEnum = pDataStats.UniqueValues
        pEnum.Reset()
        Do While pEnum.MoveNext
            ComboBox1.Items.Add(pEnum.Current)
        Loop


Is there a way to request all values instead of UniqueValues? thank you
0 Kudos
5 Replies
DavidBirkigt
New Contributor III
Hi,

Here is some VBA code that will list the attributes of a field in a combobox. It will not be too difficult to adapt the code to .net. I apologize in advance for providing VBA code.

    Dim pTable As ITable
    Set pTable = pFeatureClass         'Set a table object to the desired feature class
                 
    'I like to sort the rows before listing them
    'The following section accomplishes this
    
    Dim pTableSort As ITableSort
    Set pTableSort = New TableSort      'Instantiate a new table sort
                                
    With pTableSort
        .Fields = strField                   'Set the field to sort to the desired field
        .Ascending(strField) = True     'Sort assending (smallest to largest)
        Set .table = pTable               'Pass the table to sort
    End With
            
    pTableSort.Sort Nothing             'Sort the table/field
                      
    Dim pCatchCursor As ICursor
    Set pCatchCursor = pTableSort.Rows   'Pass the sorted field's rows to a cursor
                                 
    Dim pRow As IRow
    Set pRow = pCatchCursor.NextRow      'Use the next method to access the first row
           
    frmMain.cboAtt.Clear                 'Clear the combobox
     
    Dim j As Integer                       'j is a counter variable
    
   'This loop goes through each row and adds the value to the combobox
   For j = 0 To pTable.RowCount(Nothing) - 1
        frmMain.cboAtt.AddItem pRow.Value(4)        '4 is the index of my desired field
       Set pRow = pCatchCursor.NextRow               'Load the next row
   Next
0 Kudos
JohnMcCrae1
New Contributor
David thanks for the response, I was able to adapt the code as you said to get a working result
0 Kudos
pavankalvala
New Contributor
Hi,

I am trying to loop through the field names and get field values when a feature is identified.

Is there a way to programamtically loop through the field names from an identify wdialog and popultae the field values in a word document.

I created a doc template with few bookmarks, so that I can popultae these field values to the bookmark in Word doc.

Please help me.
0 Kudos
pavankalvala
New Contributor
I am populating field values from selected features onto a word document bookmark. I need code help in assigning the value to the bookmark range in c#.

Here is the code I am currently working with C#.

// opening word application
wdApp = new Microsoft.Office.Interop.Word.Application();
wdApp.Visible = true;
wdApp.WindowState = WdWindowState.wdWindowStateMaximize;

// opening the word document from config file
wddoc = wdApp.Documents.Add(ConfigurationSettings.AppSettings["WordDocumentPath"]);

{
var with = wddoc.Bookmarks;

with.item("A").Range.InsertAfter(A); // @@@ help here:
}
}

with.item is not acceptable in the c#. getting error at . item. What do I write In order to make it work in C#. Please help.
0 Kudos
JamesCrandall
MVP Frequent Contributor
Hi,

I am trying to loop through the field names and get field values when a feature is identified.

Is there a way to programamtically loop through the field names from an identify wdialog and popultae the field values in a word document.

I created a doc template with few bookmarks, so that I can popultae these field values to the bookmark in Word doc.

Please help me.


The most simple solution would be to setup a MS Word Doc for a MailMerge, where the datasource is the actual table or featureclass you are attempting to "loop thru".  Then it's just a matter of opening that word document from your ArcGIS application.
0 Kudos