I'm currently trying to rewrite one of my applications with the xamDataGrid.Before that i used the WPFToolkit datagrid.
I need to bind with Styles in the code behind.
This does work:
CellStyle.Setters.Add(new Setter() { Property = CellValuePresenter.TagProperty, Value = new Binding("DataItem.[2008].Flag") } );
This doesn't work:
CellStyle.Setters.Add(new Setter() { Property = CellValuePresenter.IsSelectedProperty, Value = new Binding("DataItem.[2008].IsSelected") } );
It is basically the same operation, but for some reason the IsSelectedProperty doesn't execute the binding.
With WPFToolkit grid this still works and though i know that there are better ways to accomplish this task with the xamDataGrid, i would have to rewrite much of my coding.
Does anybody know what i can do, or what is different with the IsSelectedProperty??
ThxJohannes
If someone should ever need this, here is a more solid version of the workaroung:
#region mainGrid_SelectedItemsChanging //workaround!!! private void mainGrid_SelectedItemsChanging(object sender, Infragistics.Windows.DataPresenter.Events.SelectedItemsChangingEventArgs e) { //Unselect all previous selected DataPoints ManageDataPointSelection(mainGrid, mainGrid.SelectedItems, false); //Select all new Datapoints ManageDataPointSelection(mainGrid, e.NewSelection, true); } #endregion //mainGrid_SelectedItemsChanging #region ManageDataPointSelection /// <summary> /// Manages the selection of the DataPoints. /// </summary> /// <param name="grid">the grid</param> /// <param name="selectedItems">The collection of selectedItems of the grid</param> /// <param name="select">Determines wheter to select (true) or unselect (false) the dataPoints</param> public void ManageDataPointSelection(XamDataGrid grid, DataPresenterBase.SelectedItemHolder selectedItems, bool select) { Model.Indicator indicator = null; Model.DataPoint dataPoint = null; //SelectedCells if (selectedItems.Cells.Count > 0) { foreach (Cell cell in selectedItems.Cells) { indicator = (Model.Indicator)cell.Record.DataItem; dataPoint = (Model.DataPoint)indicator[cell.Field.Label.ToString()]; if (dataPoint != null) dataPoint.IsSelected = select; } } //SelectedRecords else if (selectedItems.Records.Count > 0) { foreach (DataRecord record in selectedItems.Records) { indicator = (Model.Indicator)record.DataItem; if (!select) indicator.clearSelectedDataPoints(); else { indicator.SelectDataPoints(); } } } //SelectedFields else if (selectedItems.Fields.Count > 0) { foreach (DataRecord record in grid.Records) { foreach (Field field in selectedItems.Fields) { indicator = (Model.Indicator)record.DataItem; dataPoint = (Model.DataPoint)indicator[field.Label.ToString()]; if (dataPoint != null) dataPoint.IsSelected = select; } } } } #endregion //ManageDataPointSelection
I've written a workaround now, but it has a considerable impact on the selection performance.And the view doesn't update after a datapoint is selected in another view or by code.So still looking for input!
FYI: The Datagrid binds to a collection of Indicators. Those indicators have a collection of Datapoints.The Datagrid shows the name of the indicator and then the datapoints (datapoint amount is different for each indicator).
Workaround using SelectedItemsChanging:
private void mainGrid_SelectedItemsChanging(object sender, Infragistics.Windows.DataPresenter.Events.SelectedItemsChangingEventArgs e) { Model.Indicator indicator = null; Model.DataPoint dataPoint = null; SelectedCellCollection collection = mainGrid.SelectedItems.Cells; bool selected = false; //Do it once for the old selection and once for the new selection for (int i = 0; i <= 1; i++) { foreach (Cell cell in collection) { indicator = (Model.Indicator)cell.Record.DataItem; dataPoint = (Model.DataPoint)indicator[cell.Field.Label.ToString()]; dataPoint.IsSelected = selected; } selected = true; collection = e.NewSelection.Cells; } }
Thx