<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multi select from datagrid in ArcGIS Pro SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1362366#M10896</link>
    <description>&lt;P&gt;hi mody, this actually proved to be a lot trickier than I expected. Seems Datagrid is not "fully" WPF compliant - it does not have a dependency property for its selected items (the way, say a ListBox or ComboBox has).&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project&lt;/A&gt;&amp;nbsp;gave some options for a solution. I went with this one:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&lt;SPAN&gt;One way to to what you want is to register the&amp;nbsp;&lt;/SPAN&gt;SelectionChanged e&lt;SPAN&gt;vent of the DataGrid to update the property of your ViewModel, that stores the selected items.&amp;lt;&amp;lt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Sub-classing the Datagrid and adding a dependency property for the selected items is a more sophisticated way to go for sure, and is explained in the stackoverflow post, but using the "SelectionChanged" event on the datagrid is v straighforward and this, at least, should get u pointed in the right direction.&lt;/P&gt;&lt;P&gt;I will get this added as a sample to community samples for a complete solution. It's too much code to paste here in its entirety.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;UserControl x:Class="DatagridMultiSelect.UI.DataGridDockpaneView"
             ....&amp;gt;
  ....
  &amp;lt;Grid&amp;gt;
    ....

    &amp;lt;DataGrid Grid.Row="1" HorizontalAlignment="Stretch" Height="Auto" 
              ItemsSource="{Binding FeatureData}" VerticalAlignment="Top" 
              x:Name="dataGrid"
              Style="{DynamicResource Esri_DataGrid}"
              HeadersVisibility="Column"
              AutoGenerateColumns="True"
              IsReadOnly="True"
              SelectionMode="Extended"
              SelectionUnit="FullRow"
              CanUserSortColumns="True"
              RowHeaderWidth="0" Margin="0,0,5,0"/&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code behind of the view:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public partial class DataGridDockpaneView : UserControl {
 public DataGridDockpaneView()
 {
   InitializeComponent();
   this.Loaded += DataGridDockpaneView_Loaded;
 }

 private void DataGridDockpaneView_Loaded(object sender, RoutedEventArgs e)
 {
   var dg_vm = this.DataContext as DataGridDockpaneViewModel;
   dg_vm.SetDataGrid(this.dataGrid);
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and in the dockpane view model:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class DataGridDockpaneViewModel : DockPane
  {
    private const string _dockPaneID = "DatagridMultiSelect_UI_DataGridDockpane";
    private DataGrid _dataGrid = null;
    private static readonly object _lock = new object();

  internal void SetDataGrid(DataGrid dataGrid) {
    _dataGrid = dataGrid;//wire up the datagrid
    //From:https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project
    _dataGrid.SelectionChanged += (o, e) =&amp;gt; {
        var grid = o as DataGrid;
        var selected = grid.SelectedItems;
        lock (_lock) {
          //"MyRecord" is whatever your custom DataGrid
          //content items are...
          var sel_fd = selected.OfType&amp;lt;MyRecord&amp;gt;().ToList();
          //TODO - use the selection from the grid...
          //
        }
      };
    }
    ...

//Elsewhere:
internal class MyRecord
  {
    //your custom class
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Dec 2023 01:07:23 GMT</pubDate>
    <dc:creator>CharlesMacleod</dc:creator>
    <dc:date>2023-12-19T01:07:23Z</dc:date>
    <item>
      <title>Multi select from datagrid</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1361838#M10884</link>
      <description>&lt;P&gt;Hello all&lt;/P&gt;&lt;P&gt;This is a pure mvvm question.&lt;/P&gt;&lt;P&gt;I have a datagrid in dockpane. I would like to let the user select many records (using control or shift) so I set the selectionmode to extended (the other option is single).&lt;/P&gt;&lt;P&gt;I set the property in the model view to object so I get something.&lt;/P&gt;&lt;P&gt;When I select one record the property set is activated and I get the selected record.&lt;/P&gt;&lt;P&gt;When I use the shift or control to add more records to the selected the property is not called.&lt;/P&gt;&lt;P&gt;The is working with ListBox where the property is&amp;nbsp;ObservableCollection&amp;lt;MyRecord&amp;gt; but I could not find similar example with DataGrid.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 17 Dec 2023 18:50:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1361838#M10884</guid>
      <dc:creator>mody_buchbinder</dc:creator>
      <dc:date>2023-12-17T18:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multi select from datagrid</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1362366#M10896</link>
      <description>&lt;P&gt;hi mody, this actually proved to be a lot trickier than I expected. Seems Datagrid is not "fully" WPF compliant - it does not have a dependency property for its selected items (the way, say a ListBox or ComboBox has).&lt;/P&gt;&lt;P&gt;&lt;A href="https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project" target="_blank" rel="noopener"&gt;https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project&lt;/A&gt;&amp;nbsp;gave some options for a solution. I went with this one:&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&lt;SPAN&gt;One way to to what you want is to register the&amp;nbsp;&lt;/SPAN&gt;SelectionChanged e&lt;SPAN&gt;vent of the DataGrid to update the property of your ViewModel, that stores the selected items.&amp;lt;&amp;lt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Sub-classing the Datagrid and adding a dependency property for the selected items is a more sophisticated way to go for sure, and is explained in the stackoverflow post, but using the "SelectionChanged" event on the datagrid is v straighforward and this, at least, should get u pointed in the right direction.&lt;/P&gt;&lt;P&gt;I will get this added as a sample to community samples for a complete solution. It's too much code to paste here in its entirety.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;UserControl x:Class="DatagridMultiSelect.UI.DataGridDockpaneView"
             ....&amp;gt;
  ....
  &amp;lt;Grid&amp;gt;
    ....

    &amp;lt;DataGrid Grid.Row="1" HorizontalAlignment="Stretch" Height="Auto" 
              ItemsSource="{Binding FeatureData}" VerticalAlignment="Top" 
              x:Name="dataGrid"
              Style="{DynamicResource Esri_DataGrid}"
              HeadersVisibility="Column"
              AutoGenerateColumns="True"
              IsReadOnly="True"
              SelectionMode="Extended"
              SelectionUnit="FullRow"
              CanUserSortColumns="True"
              RowHeaderWidth="0" Margin="0,0,5,0"/&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code behind of the view:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public partial class DataGridDockpaneView : UserControl {
 public DataGridDockpaneView()
 {
   InitializeComponent();
   this.Loaded += DataGridDockpaneView_Loaded;
 }

 private void DataGridDockpaneView_Loaded(object sender, RoutedEventArgs e)
 {
   var dg_vm = this.DataContext as DataGridDockpaneViewModel;
   dg_vm.SetDataGrid(this.dataGrid);
 }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and in the dockpane view model:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;internal class DataGridDockpaneViewModel : DockPane
  {
    private const string _dockPaneID = "DatagridMultiSelect_UI_DataGridDockpane";
    private DataGrid _dataGrid = null;
    private static readonly object _lock = new object();

  internal void SetDataGrid(DataGrid dataGrid) {
    _dataGrid = dataGrid;//wire up the datagrid
    //From:https://stackoverflow.com/questions/22868445/select-multiple-items-from-a-datagrid-in-an-mvvm-wpf-project
    _dataGrid.SelectionChanged += (o, e) =&amp;gt; {
        var grid = o as DataGrid;
        var selected = grid.SelectedItems;
        lock (_lock) {
          //"MyRecord" is whatever your custom DataGrid
          //content items are...
          var sel_fd = selected.OfType&amp;lt;MyRecord&amp;gt;().ToList();
          //TODO - use the selection from the grid...
          //
        }
      };
    }
    ...

//Elsewhere:
internal class MyRecord
  {
    //your custom class
  }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2023 01:07:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1362366#M10896</guid>
      <dc:creator>CharlesMacleod</dc:creator>
      <dc:date>2023-12-19T01:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multi select from datagrid</title>
      <link>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1621599#M12975</link>
      <description>&lt;P&gt;This has been logged as an issue here:&amp;nbsp;&lt;A href="https://github.com/dotnet/wpf/issues/3140" target="_blank"&gt;https://github.com/dotnet/wpf/issues/3140&lt;/A&gt;. If you agree that multi-select should be out-of-the-box functionality for WPF DataGrids, please consider upvoting this issue!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jun 2025 17:11:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-sdk-questions/multi-select-from-datagrid/m-p/1621599#M12975</guid>
      <dc:creator>Jeff-Reinhart</dc:creator>
      <dc:date>2025-06-06T17:11:31Z</dc:date>
    </item>
  </channel>
</rss>

