Button in a GridDataControl, DaaContext issue
<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.
Hi Francis,
We are sorry for delay,
We have analyzed your query. When you want to get current
record from the button click event you have to convert DataContext as
GridDataCellBoundWrapper Class, from that you can get the Record and you have
to typecast with RecodEntry. Now you can able to get the current record. You can
also refer the below codesnippet.
Codesnippet[C#]:
|
private void cmdOpenUnit_Click(object
sender, RoutedEventArgs e) { var
data = ((Button)sender).DataContext as GridDataCellBoundWrapper; var
style = data.Record as RecordEntry; var
record = style.Data as Data; }
|
We have prepared a sample based on your requirement,
please find the attached sample below,
Please let us know if this helps you,
Regards,
Saravanan.M
GDC_Sample_e7421fd4.zip
Hi Francis,
Thanks for your update.
Regards,
Saravanan.M
- 3 Replies
- 2 Participants
-
FR Francis Rouleau
- Nov 15, 2013 01:24 PM UTC
- Nov 26, 2013 04:02 AM UTC