Select and Flash in C#

680
4
Jump to solution
03-26-2012 01:19 AM
Highlighted
New Contributor III
Hi guys

Tell me please how can I select object from layer and then flash it. The name of object i write in textbox.

I try to use whereclause to find the object but i can't understand how use textbox with this option...(
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
New Contributor III
C# Flash Code 

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000075000000

ComboBox ListBox Where Clause example calling Flash Geometry 

private void btnZoom_Click(object sender, EventArgs e) 

try 

string strWhere; 
Boolean boStatus = ckbQuery.Checked; 
IMxDocument IMxDoc = (IMxDocument)ArcMap.Application.Document; 
ILayer iLayer1; 
//HARD CODED 
//Build where Clause 
if (rdName.Checked) 

strWhere = "Allot_NAME = '" +   listName.SelectedItem.ToString() + "' AND " + "ADM_OFC_CD = '" +   cmbOffice.Text + "'"; 

else 

strWhere = "ST_ALLOT = 'ID" + listNumber.SelectedItem.ToString() + "'"; 

//Hard Coded 
if (iLayer != null) 

iLayer1 = cUtils.ExistsFeatureReturnLayer((IMap)IMxDoc.FocusMap, iLayer); 
if (iLayer1 != null) 

   cUtils.SelectFeatureQuery(iLayer1, strWhere, boStatus);
else 

cUtils.AddLayerToActiveView(IMxDoc.ActiveView, iLayer); 
IMxDoc.ActiveView.Refresh(); 
cUtils.SelectFeatureQuery(iLayer, strWhere, boStatus); 



catch 






   public void SelectFeatureQuery(ILayer iLayer, string sQuery, Boolean bDef)  

IFeatureLayer iFeatureLayer = iLayer as IFeatureLayer; 
IFeatureLayerDefinition iFLD = iFeatureLayer as IFeatureLayerDefinition; 
IFeatureSelection iFeatureSelection = iFeatureLayer as IFeatureSelection; 
IQueryFilter iQF = new QueryFilter(); 
ISelectionSet iSelSet; 
try 

UID uUID = new UID(); 
uUID.Value = "esriArcMapUI.ClearSelectionCommand"; 
ArcMap.Application.Document.CommandBars.Find(uUID).Execute(); 
if (bDef) 

iFLD.DefinitionExpression = sQuery; 

else 

iFLD.DefinitionExpression = ""; 


iQF.WhereClause = sQuery;  
iFeatureSelection.SelectFeatures(iQF, esriSelectionResultEnum.esriSelectionResultNew, false); 
iFeatureSelection.SelectionChanged(); 

iSelSet = iFeatureSelection.SelectionSet; 
if (iFeatureSelection.SelectionSet.Count == 0) 

MessageBox.Show("Feature Not Found!", "Query Results"); 

else 

uUID.Value = "esriArcMapUI.ZoomToSelectedCommand"; 
ArcMap.Application.Document.CommandBars.Find(uUID).Execute(); 

//example passing flash parameters delete 
Application.DoEvents(); 
FeatureClassUtils fc = new FeatureClassUtils(); 
IFeature feature = iFeatureLayer.FeatureClass.GetFeature(iSelSet.IDs.Next()); 
IGeometry ig = feature.Shape; 
IRgbColor iColor = new RgbColor(); 
iColor.RGB = 233; 
IMxDocument iMxDoc = ArcMap.Document; 

fc.FlashGeometry(ig, iColor, iMxDoc.ActiveView.ScreenDisplay, 1000); 


catch 



}


:eek: thank you!!! can i write you if will i have any ather questions?)

View solution in original post

Reply
0 Kudos
4 Replies
Highlighted
New Contributor III
Please see the work flow in the sample available at http://support.esri.com/en/knowledgebase/techarticles/detail/20500
Reply
0 Kudos
Highlighted
New Contributor III
Please see the work flow in the sample available at http://support.esri.com/en/knowledgebase/techarticles/detail/20500


thanks

but how do it in c# ( i don't know VB 😞 )
Reply
0 Kudos
Highlighted
New Contributor III
C# Flash Code

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000075000000

ComboBox ListBox Where Clause example calling Flash Geometry

private void btnZoom_Click(object sender, EventArgs e)
{
try
{
string strWhere;
Boolean boStatus = ckbQuery.Checked;
IMxDocument IMxDoc = (IMxDocument)ArcMap.Application.Document;
ILayer iLayer1;
//HARD CODED
//Build where Clause
if (rdName.Checked)
{
strWhere = "Allot_NAME = '" + listName.SelectedItem.ToString() + "' AND " + "ADM_OFC_CD = '" + cmbOffice.Text + "'";
}
else
{
strWhere = "ST_ALLOT = 'ID" + listNumber.SelectedItem.ToString() + "'";
}
//Hard Coded
if (iLayer != null)
{
iLayer1 = cUtils.ExistsFeatureReturnLayer((IMap)IMxDoc.FocusMap, iLayer);
if (iLayer1 != null)
{
cUtils.SelectFeatureQuery(iLayer1, strWhere, boStatus); }
else
{
cUtils.AddLayerToActiveView(IMxDoc.ActiveView, iLayer);
IMxDoc.ActiveView.Refresh();
cUtils.SelectFeatureQuery(iLayer, strWhere, boStatus);
}
}
}
catch
{
}
}



public void SelectFeatureQuery(ILayer iLayer, string sQuery, Boolean bDef)
{
IFeatureLayer iFeatureLayer = iLayer as IFeatureLayer;
IFeatureLayerDefinition iFLD = iFeatureLayer as IFeatureLayerDefinition;
IFeatureSelection iFeatureSelection = iFeatureLayer as IFeatureSelection;
IQueryFilter iQF = new QueryFilter();
ISelectionSet iSelSet;
try
{
UID uUID = new UID();
uUID.Value = "esriArcMapUI.ClearSelectionCommand";
ArcMap.Application.Document.CommandBars.Find(uUID).Execute();
if (bDef)
{
iFLD.DefinitionExpression = sQuery;
}
else
{
iFLD.DefinitionExpression = "";
}

iQF.WhereClause = sQuery;
iFeatureSelection.SelectFeatures(iQF, esriSelectionResultEnum.esriSelectionResultNew, false);
iFeatureSelection.SelectionChanged();

iSelSet = iFeatureSelection.SelectionSet;
if (iFeatureSelection.SelectionSet.Count == 0)
{
MessageBox.Show("Feature Not Found!", "Query Results");
}
else
{
uUID.Value = "esriArcMapUI.ZoomToSelectedCommand";
ArcMap.Application.Document.CommandBars.Find(uUID).Execute();

//example passing flash parameters delete
Application.DoEvents();
FeatureClassUtils fc = new FeatureClassUtils();
IFeature feature = iFeatureLayer.FeatureClass.GetFeature(iSelSet.IDs.Next());
IGeometry ig = feature.Shape;
IRgbColor iColor = new RgbColor();
iColor.RGB = 233;
IMxDocument iMxDoc = ArcMap.Document;

fc.FlashGeometry(ig, iColor, iMxDoc.ActiveView.ScreenDisplay, 1000);
}
}
catch
{
}

}
Reply
0 Kudos
Highlighted
New Contributor III
C# Flash Code 

http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000075000000

ComboBox ListBox Where Clause example calling Flash Geometry 

private void btnZoom_Click(object sender, EventArgs e) 

try 

string strWhere; 
Boolean boStatus = ckbQuery.Checked; 
IMxDocument IMxDoc = (IMxDocument)ArcMap.Application.Document; 
ILayer iLayer1; 
//HARD CODED 
//Build where Clause 
if (rdName.Checked) 

strWhere = "Allot_NAME = '" +   listName.SelectedItem.ToString() + "' AND " + "ADM_OFC_CD = '" +   cmbOffice.Text + "'"; 

else 

strWhere = "ST_ALLOT = 'ID" + listNumber.SelectedItem.ToString() + "'"; 

//Hard Coded 
if (iLayer != null) 

iLayer1 = cUtils.ExistsFeatureReturnLayer((IMap)IMxDoc.FocusMap, iLayer); 
if (iLayer1 != null) 

   cUtils.SelectFeatureQuery(iLayer1, strWhere, boStatus);
else 

cUtils.AddLayerToActiveView(IMxDoc.ActiveView, iLayer); 
IMxDoc.ActiveView.Refresh(); 
cUtils.SelectFeatureQuery(iLayer, strWhere, boStatus); 



catch 






   public void SelectFeatureQuery(ILayer iLayer, string sQuery, Boolean bDef)  

IFeatureLayer iFeatureLayer = iLayer as IFeatureLayer; 
IFeatureLayerDefinition iFLD = iFeatureLayer as IFeatureLayerDefinition; 
IFeatureSelection iFeatureSelection = iFeatureLayer as IFeatureSelection; 
IQueryFilter iQF = new QueryFilter(); 
ISelectionSet iSelSet; 
try 

UID uUID = new UID(); 
uUID.Value = "esriArcMapUI.ClearSelectionCommand"; 
ArcMap.Application.Document.CommandBars.Find(uUID).Execute(); 
if (bDef) 

iFLD.DefinitionExpression = sQuery; 

else 

iFLD.DefinitionExpression = ""; 


iQF.WhereClause = sQuery;  
iFeatureSelection.SelectFeatures(iQF, esriSelectionResultEnum.esriSelectionResultNew, false); 
iFeatureSelection.SelectionChanged(); 

iSelSet = iFeatureSelection.SelectionSet; 
if (iFeatureSelection.SelectionSet.Count == 0) 

MessageBox.Show("Feature Not Found!", "Query Results"); 

else 

uUID.Value = "esriArcMapUI.ZoomToSelectedCommand"; 
ArcMap.Application.Document.CommandBars.Find(uUID).Execute(); 

//example passing flash parameters delete 
Application.DoEvents(); 
FeatureClassUtils fc = new FeatureClassUtils(); 
IFeature feature = iFeatureLayer.FeatureClass.GetFeature(iSelSet.IDs.Next()); 
IGeometry ig = feature.Shape; 
IRgbColor iColor = new RgbColor(); 
iColor.RGB = 233; 
IMxDocument iMxDoc = ArcMap.Document; 

fc.FlashGeometry(ig, iColor, iMxDoc.ActiveView.ScreenDisplay, 1000); 


catch 



}


:eek: thank you!!! can i write you if will i have any ather questions?)

View solution in original post

Reply
0 Kudos