I don't see anywhere in the code you posted where you are creating a feature class, or a feature for that matter. Your code is drawing a point on the display. Unless you put this code in the active view's AfterDraw event, it will simply draw once and then disappear on the next refresh of the display because it's simply a graphic and is not permanent. If you want to create a new feature from the point and save it into a feature class then that is completely different than what you are doing in the code you posted. There are examples that show how to create new features in the developer samples and here on the forums.
*EDIT - WORKING*
I took a slightly different approach to this and it seems to be working in the dataview... Code is edited to reflect current working solution. Any suggestions to clean this up or make it better would still be greatly appreciated!Hello and thanks for the reply. I tried to post all of the code but it told me it was too many characters. I only posted the drawing part to see if I was going about the drawing correctly and to get suggestions on where to place it within the featureClass creation method. Can you point me to these samples, because I am creating the FC just fine but not with the symbol. I thought I was doing something wrong with my drawing.Simplified Code:
IFields fields = new FieldsClass();
IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
IField oidField = new FieldClass();
IFieldEdit oidFieldEdit = (IFieldEdit)oidField;
oidFieldEdit.Name_2 = "OID";
oidFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
fieldsEdit.AddField(oidField);
//create geometry definition and spatial reference for the featureclass
IGeometryDef geometryDef = new GeometryDefClass();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
ISpatialReferenceFactory spatialRefFactory = new SpatialReferenceEnvironmentClass();
int coordinateSystemID = (int)esriSRGeoCSType.esriSRGeoCS_WGS1984;
ISpatialReference spatialReference = spatialRefFactory.CreateGeographicCoordinateSystem(coordinateSystemID);
IField geometryField = new FieldClass();
IFieldEdit geometryFieldEdit = (IFieldEdit)geometryField;
//field = new FieldClass();
geometryFieldEdit.Name_2 = "Shape";
geometryFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
geometryFieldEdit.GeometryDef_2 = geometryDef;
fieldsEdit.AddField(geometryField);
//Create fields
IField A2Field = new FieldClass();
IFieldEdit A2FieldEdit = (IFieldEdit)A2Field;
A2FieldEdit.Name_2 = "ISO_A2";
A2FieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
A2FieldEdit.Length_2 = 254;
fieldsEdit.AddField(A2Field);
// Use IFieldChecker to create a validated fields collection
IFieldChecker fieldChecker = new FieldCheckerClass();
IEnumFieldError enumFieldError = null;
IFields validatedFields = null;
fieldChecker.ValidateWorkspace = (IWorkspace)fws;
fieldChecker.Validate(fields, out enumFieldError, out validatedFields);
IFeatureClass featureClass = fws.CreateFeatureClass(fcName, validatedFields, null, null , esriFeatureType.esriFTSimple, "Shape", "");
MessageBox.Show(fcName + " Has been created successfully!");
IFeatureClass fc = fws.OpenFeatureClass(fcName);
IFeatureLayer fl = new FeatureLayerClass();
fl.Name = fcName;
fl.FeatureClass = fc;
IMxDocument mxDoc = (IMxDocument)ArcMap.Application.Document;
IMap map = mxDoc.FocusMap;
map.AddLayer(fl);
IEnumLayer enumLayer = map.Layers;
ILayer layer = enumLayer.Next();
IFeatureLayer2 pointLayer = null;
while (layer != null)
{
if (layer.Name == fcName && layer is IFeatureLayer2)
{
pointLayer = layer as IFeatureLayer2;
}
layer = enumLayer.Next();
}
if (pointLayer == null)
{
MessageBox.Show("No layer!");
return;
}
try
{
//set coordinates
double xCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[6].Text);
double yCoor = Convert.ToDouble(listVariants.SelectedItems[0].SubItems[7].Text);
IFeature newPoint = pointLayer.FeatureClass.CreateFeature();
IPoint placePoint = new PointClass();
placePoint.PutCoords(yCoor, xCoor);
newPoint.Shape = placePoint;
IFeatureClass pointFClass = pointLayer.FeatureClass;
int fieldCOUNTRY = pointFClass.Fields.FindField("COUNTRY");
newPoint.Value[fieldCOUNTRY] = listVariants.SelectedItems[0].SubItems[5].Text;
newPoint.Store();
}
catch (Exception ex)
{
new MessageDialogClass().DoModal(ex.Source, ex.Message, "", "", ArcMap.Application.hWnd);
}
I'm very new to ArcObjects so any help suggestions are greatly appreciated!CheersChris