| So, we are using an older version of the Grid control. Kinda stuck with it for now because we are at the very end of product development and we can't afford to be changing anything at this point. I have had an annoying problem for awhile that has been a lower bug issue, but now I'm finally getting to it. I'm assuming the developers used this method of binding data to the cell because this was the only way to use a converter. But this is messing up the default cell style. the cell doesn't look like the other cells. It's kinda a pain to go into every instance of the grid we are using in the application and fix the style where they have overridden the template. Question: Is this the best way to do this? Is there a better way to do this binding without overriding the template? Again, we can't update the control. We are stuck with 2009.1.312.35 for now. <telerik:GridViewDataColumn UniqueName="UserNames" |
| HeaderText="{x:Static properties:Resources.Population_GridHeader_UserName}"> |
| <telerik:GridViewColumn.CellStyle> |
| <Style TargetType="{x:Type telerik:GridViewCell}"> |
| <Setter Property="Template"> |
| <Setter.Value> |
| <ControlTemplate TargetType="{x:Type telerik:GridViewCell}"> |
| <Border BorderThickness="{TemplateBinding BorderThickness}" |
| BorderBrush="{TemplateBinding BorderBrush}" |
| Background="{TemplateBinding Background}"> |
| <TextBlock Text="{Binding Path=UserNames, Mode=OneWay, Converter={StaticResource UserNameListToStringConverter}}" |
| VerticalAlignment="Center" |
| Margin="5" /> |
| </Border> |
| </ControlTemplate> |
| </Setter.Value> |
| </Setter> |
| </Style> |
| </telerik:GridViewColumn.CellStyle> |
| </telerik:GridViewDataColumn> |

| <Style x:Key="CustomRowStyle" TargetType="telerik:GridViewGroupRow"> |
| <EventSetter Event="Loaded" Handler="GridViewGroupRow_Loaded" /> |
| </Style> |
| private void GridViewGroupRow_Loaded(object sender, RoutedEventArgs args) |
| { |
| GridViewGroupRow groupRow = (GridViewGroupRow)args.OriginalSource; |
| CheckBox cb = new CheckBox() { Content = groupRow.Group.Key }; |
| cb.Tag = groupRow; |
| cb.Checked += new RoutedEventHandler(groupRow_CheckChanged); |
| cb.Unchecked += new RoutedEventHandler(groupRow_CheckChanged); |
| groupRow.Header = cb; |
| } |
| void groupRow_CheckChanged(object sender, RoutedEventArgs e) |
| { |
| GridViewGroupRow groupRow = (sender as CheckBox).Tag as GridViewGroupRow; |
| recursiveGroupSelection(groupRow.Group, (sender as CheckBox).IsChecked ?? false); |
| } |
| private void recursiveGroupSelection(IGroup g, bool check) |
| { |
| foreach (var item in g.Items)//select items in this group |
| { |
| if (item is BusinessObject) |
| { |
| (item as BusinessObject).IsSelected = check; |
| } |
| } |
| //the same for all subgroups |
| foreach (Group sub in g.Subgroups) |
| { |
| recursiveGroupStationSelection(sub, check); |
| } |
| } |
Ok,
Getting closer to having the grid beaten into shape. Just two more things to solve. In this post, let's deal with detecting the change of an underlying data record.
The grid is clearly NOTICING the record data changes, as they are reflected in real time. If I change the data via my detail window, the grid column updates instantly and automatically. However, the grouping is not re-evaluated, so if the change would place the row in a different group it does not move.
I need to detect the data change, and then re-group the grid so that this change happens. However neither SourceUpdated() or DataContextChanged() fire – so I am clearly looking in the wrong places :)
Any hints?
Ken
internal void BuildReportObjectCollection()
{
List<ReportObjectEntity> reportObjectCollection =
Presenter.buildReportObjectCollection();
SingleObjectList.DataContext = reportObjectCollection;
}
//Use the list of Guids to filter my collection using
//the predicate here
public void Show(List<Guid> reportObjectList)
{
selectdReportObjectCollection = reportObjectList;
if (selectdReportObjectCollection != null)
{
if (SingleObjectList.ItemsSource != null)
{
// filter
collectionView =
CollectionViewSource.GetDefaultView(SingleObjectList.DataContext);
collectionView.Filter =
new Predicate<object>(FilterForSelectedReportObjectList);
}
}
}
public
bool FilterForSelectedReportObjectList(object item)
{
ReportObjectEntity reportObject = item as ReportObjectEntity;
if (reportObject != null && this.selectdReportObjectCollection.Contains(reportObject.ReportObjectID))
{
return true;
}
else
{
return false;
}
}
//The XAML is pretty standard for the GridView, ItemsSource = {Binding}
Does anyone know what is the issue here?
Thanks,