Selection set question

Discussion created by kyanuk1 on Aug 2, 2012
Latest reply on Sep 21, 2012 by rwmeier

I have an Add-in which when the user clicks a button, it selects a feature based on a listbox item that is populated with a contract string from the feature's attribute table. 

When the user selects this item in the listbox, it adds the feature's OID to a list (there will be several features with the same contract value).  FeatureWrapper is simply an object created that represents the feature itself:

                OIDS.Clear(); //OID list
                if (GMContractListbox.SelectedValue == null) return;

                string contractVal = GMContractListbox.Text; //the contract from the listbox

                List<FeatureWrapper> contractList = matchList; //global list that is already populated with features.
                foreach (FeatureWrapper wrap in contractList)
                    if (Convert.IsDBNull(wrap.Feature.get_Value(wrap.Feature.Fields.FindField(contractFieldName)))) continue;
                    string contractName = wrap.Feature.get_Value(wrap.Feature.Fields.FindField(contractFieldName)).ToString();
                    if (contractName != null)
                        if (contractName == contractVal)
                            OIDS.Add(wrap.Feature.OID); //add the OID
            catch (Exception ex)

Now, there is a list of OIDS of the features with the same contract attribute - which I add to a selection set:

if (GMContractListbox.SelectedItem != null)
                    FeatureWrapper fw = (FeatureWrapper)GMContractListbox.SelectedItem;
                    fsel = (IFeatureSelection)selectionFL; 
                    foreach (int i in OIDS)

                    ArcMap.Document.ActiveView.Extent = fw.Feature.Extent;

I only was able to figure out how to zoom to a single feature using fw.  Is there a way to zoom to the features in the SelectionSet?

Also, I want to be able to change the contract attribute in the feature's attribute table WITH the tool by typing the correct contract into a text field:

 if (applyCntrctText.Text != null)
                ISelectionSet selectionSet = fsel.SelectionSet;
                ICursor cursor;
                selectionSet.Search(null, false, out cursor);

                IRow row = cursor.NextRow();
                while (row != null)
                    row.set_Value(row.Fields.FindField("Contract"), applyCntrctText.Text);
                    row = cursor.NextRow();
                MessageBox.Show("Contracts changed to " + applyCntrctText.Text);
            else return;

This kind of works, but doesn't seem to update in ArcMap correctly, and I'd like to be able to do it as if you were in an edit session and using the attribute editor to set an attribute on a bulk of features.

Is there a better way of doing this?  I'm (obviously) new to ArcObjects.