Hi, So I have a datagrid, bound to BindingList<Instrument> from my viewmodel like so:
<Grid>
<igWPF:XamDataGrid Name="SecurityBlotterGrid"
Height="Auto"
DataSource="{Binding InstrumentList}"
ExecutingCommand="SecurityBlotterGrid_ExecutingCommand"
SelectedDataItems ="{Binding selectedInstrumentList, Mode=TwoWay}"
SelectedDataItemsScope ="RecordsOnly">
<igWPF:XamDataGrid.Resources>
<Style TargetType="{x:Type igWPF:CellValuePresenter}">
<Setter Property="BorderThickness" Value="0,0,1,1"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderHoverBrush" Value="Transparent"/>
</Style>
</igWPF:XamDataGrid.Resources>
<igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:FieldLayoutSettings AllowClipboardOperations="All"
CopyFieldLabelsToClipboard="True"
HeaderPrefixAreaDisplayMode="FieldChooserButton"
AutoGenerateFields="False"
SummaryEvaluationMode="Auto"
FilterUIType="FilterRecord"
SelectionTypeRecord="Extended"/>
</igWPF:XamDataGrid.FieldLayoutSettings>
<igWPF:XamDataGrid.FieldSettings>
<igWPF:FieldSettings AllowRecordFiltering="True"
AllowSummaries="true" SummaryUIType="MultiSelect"
CellClickAction="SelectRecord"/>
</igWPF:XamDataGrid.FieldSettings>
<igWPF:XamDataGrid.FieldLayouts>
<igWPF:FieldLayout IsDefault="True">
<igWPF:FieldLayout.Fields>
[...]
and then closing tags for all.
Now, the grid populates just fine, but what I need to be able to do is have the user select one ore more records from the grid, and use those records to determine the data that shows up on a completely different viewModel.
The cleanest way I thought to achieve this was to use the part that says SelectedDataItems={Binding selectedInstrumentList, mode=TwoWay}"
and of course I have a selectedInstrumentList in my viewmodel of type BindingList<Instrument>
yet when I try to do this:
selectedInstrumentList.ListChanged += new ListChangedEventHandler(selectedInstrumentList_ListChanged);
the ListChangedEvent never occurs.
Next I tried capturing it from the codebehind which is kind of sloppy, but I want to get it done:
SecurityBlotterGrid.SelectedItemsChanged += new EventHandler<Infragistics.Windows.DataPresenter.Events.SelectedItemsChangedEventArgs>(SecurityBlotterGrid_SelectedItemsChanged);
void SecurityBlotterGrid_SelectedItemsChanged(object sender, Infragistics.Windows.DataPresenter.Events.SelectedItemsChangedEventArgs e)
{
var grid = (XamDataGrid)sender;
var instrumentArray = grid.SelectedDataItems;
if (instrumentArray != null)
var tempBinding = new BindingList<InstrumentSummary>();
ViewModel.selectedInstrumentList.Clear();
foreach (var instrument in instrumentArray)
ViewModel.selectedInstrumentList.Add((
InstrumentSummary)instrument);
}
but grid.SelectedDataItems seems to always have the previous selected item, not the one(s) i'm currently trying to select. Furthermore I have to do viewModel.selectedInstrumentList.Add((InstrumentSummary)instrument) one-at-a-time because if I try to do it en masse, the listchanged event doesn't fire on the viewmodel.
can you please explain to me what I am doing wrong?
Thanks
Hi Christian,
Thank you for your reply. I am glad that you have managed to resolve your issue.
Thank you very much!
Hi,
Thank you for your post. I have been looking into your question and the ‘SelectedDataItems’ property of the XamDataGrid is of type “object[]”:
http://help.infragistics.com/Help/Doc/WPF/2014.1/CLR4.0/html/InfragisticsWPF4.DataPresenter.v14.1~Infragistics.Windows.DataPresenter.DataPresenterBase~SelectedDataItems.html
You need to define your collection that holds the selected data items of this type, too. I am attaching a sample application(DataGrid_SelectedDataItems.zip.zip) that show this functionality.
Let me know, if you need any further assistance on this matter.