<syncfusion:SfDataGrid x:Name="grid" ItemsSource="{Binding student}" Grid.Row="0" Grid.RowSpan="2" AutoGenerateColumns="False" ShowGroupDropArea="True" AllowGrouping="True" > <syncfusion:SfDataGrid.Columns> <syncfusion:GridTextColumn HeaderText="Name" MappingName="Name" /> <syncfusion:GridTextColumn HeaderText="Age" MappingName="Age" /> <syncfusion:GridCurrencyColumn AllowScrollingOnCircle="False" CurrencyDecimalDigits="2" CurrencyPositivePattern="2" CurrencySymbol="$" HeaderText="Income" MappingName="Income" /> <syncfusion:GridCheckBoxColumn MappingName="IsCheck" HeaderText="Registered" /> <syncfusion:GridTemplateColumn HeaderText="Template Column" MappingName="Name"> <syncfusion:GridTemplateColumn.CellTemplate> <DataTemplate> <Button VerticalAlignment="Center" Height="25" Width=" 65" FontStyle="Italic" FontWeight="Bold" Content="{Binding Quantity}" Visibility="{Binding Converter={StaticResource converter}}" /> </DataTemplate> </syncfusion:GridTemplateColumn.CellTemplate> </syncfusion:GridTemplateColumn> </syncfusion:SfDataGrid.Columns> </syncfusion:SfDataGrid> |
class Converters :IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var values =(Student) value; if (values.Age == 12) return Visibility.Visible;
return Visibility.Hidden; }
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } |
public UserControl1() { InitializeComponent(); grid.CurrentCellActivated+=grid_CurrentCellActivated; }
private void grid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args) { //get the current cell var currentcell = grid.SelectionController.CurrentCellManager.CurrentCell.ColumnElement;
// search the button using Visual tree Button button = GetVisualChild<Button>(currentcell);
//current cell row data var rowdata = (Student)currentcell.DataContext;
//based on the data button visibility has been decided if (rowdata.Age != 12 && button!=null) button.Visibility = Visibility.Visible; } |
Please let me know if this solution helps you.
Thanks,
Gobikrishnan M