Row Data Bound
Thank you for contacting Syncfusion support.
We have analyzed your Query. The requirement “Show/hide buttons in template column based on row data” can be achieved in two ways. Please find the details below,
Using IValueConverter
While loading the grid, you can show/hide buttons by using IValueConverter.
XAML
|
<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> |
C#
|
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(); } } |
Using Current cell activated event
Using CurrentCellActivated event, you can change the button visibility based on row data while clicking the grid cell at run time.
C#
|
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; } |
We have also prepared the sample based on this and please find the sample under the following location
If your requirement is differ from this, could you please share more information on your requirement. This would be helpful for providing better solution.
Please let me know if this solution helps you.
Thanks,
Gobikrishnan M
- 1 Reply
- 2 Participants
-
SP saglietto piermaria
- Jul 9, 2015 12:40 PM UTC
- Jul 10, 2015 11:33 AM UTC