i needed to add a simple button in a GridDataControl. note complicated so far.
<syncfusion:GridDataVisibleColumn HeaderText="Open Unit" MappingName="JobNumber">
<syncfusion:GridDataVisibleColumn.HeaderStyle>
<syncfusion:GridDataColumnStyle HorizontalAlignment="Center" />
</syncfusion:GridDataVisibleColumn.HeaderStyle>
<syncfusion:GridDataVisibleColumn.CellItemTemplate>
<DataTemplate>
<Button HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
Name="cmdOpenUnit"
Click="cmdOpenUnit_Click"
Content="Open Unit" />
</DataTemplate>
</syncfusion:GridDataVisibleColumn.CellItemTemplate>
</syncfusion:GridDataVisibleColumn>
Now i tried the `GridDataUnboundVisibleColumn` but by using it i cannot use a mapping name since it crashes and anyway the`DataContext` is empty. So i used `GridDataUnboundVisibleColumn` and set `MappingName="JobNumber"` which is a random data in the source just to make sure i have `DataContext`
The click event :
private void cmdOpenUnit_Click(object sender, RoutedEventArgs e)
{
try
{
CUnit obj = ((Button)sender).DataContext as CUnit ;
}
catch { }
}
I have a grid with `ObservableCollection<CProject>` as Datasource then when you choose one the `CProject.UnitList // <-- ObservableCollection<CUnit>` become the Datasource of the currect grid i am working with. Therefore each row in the grid is a specific `CUnit`.
The problem is that the DataContext on `((Button)sender).DataContext` is the `JobNumber` data in the `Cunit` object and i cannot get the parent property. i tried different casting but couldn't get anything yet. I have used this method a couple time with success but it's my first time doing this with syncfusion and the help files contains nothing about that.
the DataContext of the Sender i received is of type `Syncfusion.Windows.Controls.Grid.GridDataCellBoundWrapper` if that might help.