Changing Selection Thread issue

261
2
Jump to solution
08-14-2020 08:45 AM
BrianBulla
Regular Contributor

Hi,

So in my application the user selects multiple sewer lines to start.  I then have a dockpanel that gets regfreshed to show the ID of the users selection in a listbox.  Now what I want is that when the user selects the ID of one of the lines in the dockpanel, that the selection in the map changes to show only that line as selected.  I am doing all of my coding for this in the _SelectionChanged event of the list, but running into a "The calling thread cannot access this object because a different thread owns it." error.

What can I do to get around this??

After clicking on one of the ID's in the listbox below is when the error comes up.

Thanks,

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Brian,

 I think using the ListBox on a different thread might be causing this issue.  To work around this i would try:

      var whereClause = $@"FACILITYID = '{lstFacIDs.SelectedItem}'";
      QueuedTask.Run(() =>
      {
        QueryFilter qf = new QueryFilter()
        {
          WhereClause = whereClause
        };
        gsFLayer.Select(null, SelectionCombinationMethod.Add);
      });

Also note that when you call gsFLayer.ClearSelection() that this (depending on your implementation) can cause a change in your listbox content.

View solution in original post

2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Brian,

 I think using the ListBox on a different thread might be causing this issue.  To work around this i would try:

      var whereClause = $@"FACILITYID = '{lstFacIDs.SelectedItem}'";
      QueuedTask.Run(() =>
      {
        QueryFilter qf = new QueryFilter()
        {
          WhereClause = whereClause
        };
        gsFLayer.Select(null, SelectionCombinationMethod.Add);
      });

Also note that when you call gsFLayer.ClearSelection() that this (depending on your implementation) can cause a change in your listbox content.

BrianBulla
Regular Contributor

Nice!  Very helpful.

Thanks!

0 Kudos