Dim pMxDoc As IMxDocument Set pMxDoc = Application.Document Dim pMap As IMap Set pMap = pMxDoc.FocusMap Dim pActiveView As IActiveView Set pActiveView = pMap Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pMap.Layer(0) Dim pFeatureSelection As IFeatureSelection Set pFeatureSelection = pFeatureLayer Set pTable = pFeatureLayer.FeatureClass Dim pFClass As IFeatureClass Set pFClass = pFeatureLayer.FeatureClass Dim pFCursor As IFeatureCursor Set pFCursor = pFClass.Update(Nothing, False) Dim pF As IFeature Set pF = pFCursor.NextFeature Do Until pF Is Nothing ListBox3.AddItem pF.Value(6) Set pF = pFCursor.NextFeature Loop
Solved! Go to Solution.
dim i as integer for i = 0 to pF.Fields.FieldCount - 1 if pF.Fields.Field(i).Type < 6 then 'this line adds only the numeric, text, and date field attributes, not the Shape or OID field or other types ListBox3.AddItem pF.Value(i) end if next
pQFilter.WhereClause = �??FID = " & strBEZUserForm3 &"�?�but I don't know how to proceed to read out the Features Attributes defined by that QueryFilter. (For k = 0 To pF.Fields.FieldCount - 1 just gives me the first Row (Index=0), rather then the Feature's Attributes defined by the QueryFilter)
'This is UserForm5 Private Sub UserForm_Initialize() Dim strBEZUserForm3 As String Dim strFIDUserForm3 As String Dim i As Integer Dim j As Integer 'User selected a unique Feature: Storing his choice (made in UserForm3) in ListBox1 by name (the name just aims at visualization purposes) 'and in ListBox3 by its identificationnumber (the ID is unique) For j = 0 To 550 For i = 0 To 550 If UserForm3.ListBox1.Selected(i) = True Then 'Uncomment Me: 'ListBoxXXX.AddItem UserForm3.ListBox1.List(i) strBEZUserForm3 = UserForm3.ListBox1.List(i) ListBox1.AddItem strBEZUserForm3 End If Next i If UserForm3.ListBox2.Selected(j) = True Then 'Uncomment Me: 'ListBoxXXX.AddItem UserForm3.ListBox2.List(j) strFIDUserForm3 = UserForm3.ListBox2.List(j) ListBox2.AddItem strFIDUserForm3 End If Next j 'MsgBox strBEZUserForm3 'MsgBox strFIDUserForm3 ListBox3.ColumnCount = 2 Dim pMxDoc As IMxDocument Set pMxDoc = Application.Document Dim pMap As IMap Set pMap = pMxDoc.FocusMap Dim pActiveView As IActiveView Set pActiveView = pMap Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pMap.Layer(0) Dim pFClass As IFeatureClass Set pFClass = pFeatureLayer.FeatureClass Dim pFCursor As IFeatureCursor Set pFCursor = pFClass.Update(Nothing, False) Dim pF As IFeature Set pF = pFCursor.NextFeature 'Trying to load the (User's choice) feature's attributes into ListBox3 'Trying to identify the feature by it's identificationnumber (= ID, stored in Attribute Table field "FID" / respectively stored in Listbox3) 'In theory i should loop through the Rows/features and look for the ID, 'if it is found, the programm should return the feature's attributes (like the following For-Next Loop does) 'but how to tell the programm which feature's attributes to return? 'I tried to build a Do-While-Loop around the For-Next Statement, questioning: If pF.Value(k)= strFIDUserForm3 Then 'That's not working, because it's more setting the Value rather then comparing it Dim k As Integer For k = 0 To pF.Fields.FieldCount - 1 If pF.Fields.Field(k).Type < 6 Then 'this line adds only the numeric, text, and date field attributes, not the Shape or OID field or other types ListBox3.AddItem pF.Value(k) End If Next k Unload UserForm3 End Sub
List<MyFeature> _myFeatures = new List<MyFeature>();
private void LoadTree(object sender, EventArgs e)
{
//do stuff to get your cursor
IFeature feature = cursor.NextFeature();
while ( feature != null )
{
MyFeature myFeature = new MyFeature();
myFeature.Feature = feature;
myFeature.Name = feature.Value[(feature.Fields.FindField("displayFieldName"))].ToString();
myFeature.ObjectId = feature.OID;
_myFeatures.Add(myFeature);
feature = cursor.NextFeature();
}
treeView.AfterSelect += TreeNodeSelected;
TreeNode parentNode = treeView.Nodes.Add("Features");
foreach ( var myFeature in _myFeatures )
{
TreeNode child = parentNode.Nodes.Add(myFeature.ObjectId.ToString(), myFeature.Name);
}
}
private void TreeNodeSelected(object sender, TreeViewEventArgs e)
{
MyFeature myFeature = _myFeatures.FirstOrDefault(f => f.ObjectId.ToString() == e.Node.Name);
//loop through field on myFeature.Feature like before
}
}
public class MyFeature
{
public int ObjectId { get; set; }
public string Name { get; set; }
public IFeature Feature { get; set; }
}
...
Dim pFSelection As IFeatureSelection
Set pFSelection = pFeatureLayer
Dim pFCursor As IFeatureCursor
pFSelection.SelectionSet.Search Nothing, False, pFCursor
Dim pF As IFeature
Set pF = pFCursor.NextFeature
'Hilfvariablen deklarieren
Dim intPlusIndex As Integer
Dim strAnwAuswahl As String
Dim strAnwEingabe As String
Dim strFeldName As String
If ListBox3.Selected(ListBox3.ListIndex) = True Then
intPlusIndex = ListBox3.ListIndex + 2
strAnwAuswahl = pF.Value(intPlusIndex) 'can read
MsgBox strAnwAuswahl
ListBox4.Selected(ListBox3.ListIndex) = True
strFeldName = ListBox4.Value
strAnwEingabe = InputBox("Der Wert des Feldes '" & strFeldName & "' ist '" & strAnwAuswahl & "'. Zum ändern geben Sie einen neuen Wert ein:", "Neuen Wert setzen", "Geben Sie hier den neuen Wert ein")
MsgBox strAnwEingabe
pF.Value(intPlusIndex) = strAnwEingabe 'but cannot write
pFCursor.UpdateFeature pF
'If pF.Fields.Field(intPlusIndex).Type < 4 Then
'a = CLng(strAnwEingabe)
'End If
End If
End Sub