or
<Window x:Class="WpfApplication1.Window1" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" |
Title="Group Chart Test"> |
<Grid> |
<Grid.RowDefinitions> |
<RowDefinition /> |
<RowDefinition Height="30" /> |
</Grid.RowDefinitions> |
<Grid.ColumnDefinitions> |
<ColumnDefinition /> |
<ColumnDefinition /> |
</Grid.ColumnDefinitions> |
<telerik:RadGridView Name="rgv" |
AutoGenerateColumns="False" |
Grid.Row="0" |
Grid.ColumnSpan="2"/> |
<Button Click="Button_Click" |
Grid.Row="1" |
Grid.Column="0" |
Content="Add Columns"/> |
<Button Click="Button_Click_1" |
Grid.Row="1" |
Grid.Column="1" |
Content="Add Items"/> |
</Grid> |
</Window> |
public partial class Window1 : Window |
{ |
ArrayList arrayList = new ArrayList(); |
public Window1() |
{ |
try |
{ |
InitializeComponent(); |
for (int i = 0; i < 100; i++) |
{ |
arrayList.Add(new myObject() |
{ |
Year = 2002, |
Quarter = "First", |
Make = "Chevrolet", |
Sales = 1000 |
}); |
} |
} |
catch (Exception ex) |
{ |
MessageBox.Show(ex.ToString()); |
} |
} |
private void Button_Click(object sender, RoutedEventArgs e) |
{ |
rgv.Columns.Add(new GridViewDataColumn() |
{ |
UniqueName = "Year", |
Header = "Year" |
}); |
rgv.Columns.Add(new GridViewDataColumn() |
{ |
UniqueName = "Quarter", |
Header = "Quarter" |
}); |
rgv.Columns.Add(new GridViewDataColumn() |
{ |
UniqueName = "Make", |
Header = "Make" |
}); |
rgv.Columns.Add(new GridViewDataColumn() |
{ |
UniqueName = "Sales", |
Header = "Sales" |
}); |
} |
private void Button_Click_1(object sender, RoutedEventArgs e) |
{ |
rgv.ItemsSource = arrayList; |
} |
} |
class myObject |
{ |
public int Year { get; set; } |
public String Quarter { get; set; } |
public String Make { get; set; } |
public double Sales { get; set; } |
} |
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); |
} |
} |