I have a DataGridControl which is bound to an Observable collection. This is working fine and I see my generated columns and the cells are filled in just fine.
Problem:
Now I want to add an additional column whose sole purpose is to have cells that are themselves buttons or contain buttons so that the user can click the button and do something that deals with that row the button is on.
I tried (1) adding a Column with a CellContentTemplate and a Button. On button click, however, I was unable to know which row I was on which is key in order for me to do something dealing with that row. Leaving out some details:
This is try (1)
<Grid x:Name ="ItemsGrid">
<xcdg:DataGridControl Name="MyDataGridControl"
...........
ItemsSource="{Binding Path=MyObservableCollection,....
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="AdditionalButtonColumn" Title="Perform Action">
<xcdg:Column.CellContentTemplate>
<DataTemplate>
<Button Content="Get Data" Click="GetDataButton_Click".....
</DataTemplate>
</xcdg:Column.CellContentTemplate>
</xcdg:Column>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>
</Grid>
I also tried (2) using a style and a ControlTemplate for the DataCells that will display the cells as buttons. I found how to do this in the Xceed Templates documentation. But this applies a style to all my cells for all my columns and I only want one column to have the cells as buttons.
This is try (2)
<Grid x:Name ="ItemsGrid">
<Grid.Resources>
<Style TargetType="{x:Type xcdg:DataCell}">
<EventSetter Event="MouseDown" Handler="GetData_MouseDown_Handler"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type xcdg:DataCell}">
<Button>
<Button.Content>
<ContentPresenter/>
</Button.Content>
</Button>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<xcdg:DataGridControl Name="MyDataGridControl"
...........
ItemsSource="{Binding Path=MyObservableCollection,....
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="AdditionalButtonColumn" Title="Perform Action">
</xcdg:Column>
</xcdg:DataGridControl.Columns>
</xcdg:DataGridControl>
</Grid>