The following code worked fine for weeks, but now suddenly causes my ArcMap program to crash.
The list zoningValues is supposed to contain a distinct, ordered list of zone codes. The source of the codes is the field "ZO_ZONE" from an SDE feature class (zoningFClass). In the while loop, zoningValues is first populated with the unsorted, non-distinct zoning codes. The if statement contains the LINQ query to order and make distinct the list. This part still works fine.
The final line is supposed to populate a combo box with the list values. However, this line either makes my program crash, or starts a seemingly endless loop of constantly referring back to the query. In the latter case, it's as if sortedList is a constructor object that needs to redefine itself each time.
private List<string> zoningValues = new List<string>(300);
internal void PopZoningList(IFeatureClass zoningFClass)
{
//Populate the Zoning values list
IFeatureCursor searchCursor = zoningFClass.Search(null, true);
int fieldNdx = searchCursor.FindField("ZO_ZONE");
IFeature feature = null;
//Loop through the Zoning feature class and populate a list with each ZO_ZONE value
while ((feature = searchCursor.NextFeature()) != null)
{
zoningValues.Add(feature.get_Value(fieldNdx).ToString());
feature = null;
}
//When the features are exhausted, sort the values and make them unique, then add them to the Zoning combo box
if (feature == null && zoningValues.Count >= 2)
{
//sZones is an arbitrary variable name
var sortedList = (from sZones in zoningValues
select sZones)
.Distinct().OrderBy(n => n);
cboZone.DataSource = sortedList;[/SIZE]
Thanks in advance for looking into this.
Charlie Shore