How can I select select item in attribute table and highlight on mapview?

520
3
Jump to solution
02-09-2021 12:50 AM
PitchYen
New Contributor

I using ArcGIS Pro sdk to make an addin that can select item in attribute table by defined objectid,

But my ArcGIS Pro always freeze after I run this code.

var featureLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType<FeatureLayer>().Where(fl => fl.Name.Contains("Electric Device")).FirstOrDefault();

QueryFilter queryFilter = new QueryFilter
{
WhereClause = "OBJECTID = 12227"
};

featureLayer.Select(queryFilter);

 

0 Kudos
2 Solutions

Accepted Solutions
GintautasKmieliauskas
Regular Contributor

Hi,

Select  must be called on the MCT. Use QueuedTask.Run:

await QueuedTask.Run(() =>
{
QueryFilter queryFilter = new QueryFilter
{
WhereClause = "OBJECTID = 12227"
};

featureLayer.Select(queryFilter);
});

 

View solution in original post

GintautasKmieliauskas
Regular Contributor

WhereClause = "OBJECTID IN (1, 2, ....)"

or best way to use .ObjectIDs property of QueryFilter

.ObjectIDs = oids // Where oids is List<long>

View solution in original post

3 Replies
GintautasKmieliauskas
Regular Contributor

Hi,

Select  must be called on the MCT. Use QueuedTask.Run:

await QueuedTask.Run(() =>
{
QueryFilter queryFilter = new QueryFilter
{
WhereClause = "OBJECTID = 12227"
};

featureLayer.Select(queryFilter);
});

 

View solution in original post

PitchYen
New Contributor

Thank you very much for your answer. I've created new method use your code and it work.

Maybe it freeze because I put it in using( ... ) bucket.

I have one more question

if I have to select 10000 items how can I write SQL statement for this one.

It always return message 'An invalid SQL statement was used.'

WhereClause = "OBJECTID = 1 Or OBJECTID = 137 Or ... 14355".

0 Kudos
GintautasKmieliauskas
Regular Contributor

WhereClause = "OBJECTID IN (1, 2, ....)"

or best way to use .ObjectIDs property of QueryFilter

.ObjectIDs = oids // Where oids is List<long>

View solution in original post