|
private void DataGrid_CurrentCellBeginEdit(object sender, Syncfusion.UI.Xaml.Grid.CurrentCellBeginEditEventArgs e)
{
//cancel the editing by particualrrow
if(e.RowColumnIndex.RowIndex == 1)
{
e.Cancel = true;
}
} |
|
<Window.Resources>
<local:ColorConverter x:Key="converter"/>
<Style TargetType="syncfusion:GridCell">
<Setter Property="Background" Value="{Binding Converter={StaticResource converter},RelativeSource={RelativeSource Self}}" />
</Style>
</Window.Resources> |
|
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//get the GridCell proeprty
var cell = value as GridCell;
//get the rowIndex value
var rowIndex =( cell.ColumnBase as Syncfusion.UI.Xaml.Grid.DataColumn).RowIndex;
//apply the row style for particualrrow
if (rowIndex == 1)
return new SolidColorBrush(Colors.Blue);
else
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
|
<syncfusion:SfDataGrid Name="dataGrid"
AutoGenerateColumns="False"
AllowEditing="True"
ColumnSizer="Auto"
ItemsSource="{Binding Employees}"
CurrentCellBeginEdit="DataGrid_CurrentCellBeginEdit">
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName="FirstName" />
<syncfusion:GridTextColumn MappingName="LastName" />
<syncfusion:GridTextColumn MappingName="ID"/>
<syncfusion:GridTextColumn MappingName="Title" />
<syncfusion:GridCurrencyColumn MappingName="Salary" />
<syncfusion:GridTextColumn MappingName="ReportsTo" />
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid> |
|
public class ColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
//get the GridCell proeprty
var cell = value as GridCell;
//get the rowIndex value
var rowIndex =( cell.ColumnBase as Syncfusion.UI.Xaml.Grid.DataColumn).RowIndex;
//Specific Column style achievd by Checking condition as particular mappingName
if(cell.ColumnBase.GridColumn.MappingName == "FirstName")
{
if (rowIndex != 1)
return new SolidColorBrush(Colors.Green);
}
//apply the row style for particualrrow
if (rowIndex == 1)
return new SolidColorBrush(Colors.Blue);
else
return DependencyProperty.UnsetValue;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
|
<syncfusion:SfDataGrid.Columns>
<syncfusion:GridTemplateColumn MappingName="FirstName" AllowEditing="True" >
<syncfusion:GridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding FirstName}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</syncfusion:GridTemplateColumn.CellTemplate>
<syncfusion:GridTemplateColumn.EditTemplate>
<DataTemplate>
<TextBlock Text="{Binding FirstName}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</DataTemplate>
</syncfusion:GridTemplateColumn.EditTemplate>
</syncfusion:GridTemplateColumn> |