-
satheeshpk said 11 months, 1 week ago:
Hi,
I need to change particular row border in some color in componentonegrid using C#. I tried with "row.Presenter.BorderBrush = Brushes.DarkRed;".
Still it is not set . How can I achieve this?| # -
Hello,
You may create a new RowStyle with border and then, can add it in the resources like below:
<Window.Resources > <Style x:Key="rowstyle" TargetType="c1:DataGridRowPresenter"> <Setter Property="BorderThickness" Value="0"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="c1:DataGridRowPresenter" > <Border BorderBrush="Blue" BorderThickness="3"> <Grid x:Name="Root" Margin="{TemplateBinding CellsAreaMargin}"> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name="ValidationStates"> <VisualState x:Name="Valid"/> <VisualState x:Name="InvalidUnfocused"> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetName="Validation" Storyboard.TargetProperty="(UIElement.Opacity)" Duration="0"> <DiscreteDoubleKeyFrame KeyTime="00:00:00" Value="1"/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name="InvalidFocused" > </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name="BackgroundElement" Background="{TemplateBinding Background}"/> <Border x:Name="UserBackground" Background="{TemplateBinding Background}"/> <Border x:Name="Validation" Background="#2BFF0000" Opacity="0" /> <c1:DataGridCellsPanel x:Name="Cells"/> <Rectangle x:Name="HorizontalGridLine" Grid.Row="1" Height="1" Fill="{TemplateBinding HorizontalGridLineBrush}" Visibility="{TemplateBinding HorizontalGridLineVisibility}" Opacity="{TemplateBinding HorizontalGridLineOpacity}" VerticalAlignment="Bottom"/> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources>After doing so, you may apply it on the specific row by handling the CreatingRow event of the datagrid. Here is the code for same:
int rowCounter = 0; private void c1DataGrid1_CreatingRow(object sender, C1.WPF.DataGrid.DataGridCreatingRowEventArgs e) { if (rowCounter == 1) { e.Row.RowStyle = Resources["rowstyle"] as Style; } rowCounter++; }Regards
Ashish| # -
satheeshpk said 11 months, 1 week ago:
Thanks for reply.. but when i tried that .. the value is not setting . i m using c1DataGrid inside ribbon window . so if i use " Resources["rowstyle"] as Style; " . It show as error like ,
(objDataGrid.CurrentRow.RowStyle.TargetType).Declaring method threw an exception of type 'System.InvalidOperationException’ … I am using Componentone Grid inside RibbonContol.| # -
Hello,
You may try creating style in code and then, applying it as below:
int rowCounter = 0; private void c1DataGrid1_CreatingRow(object sender, C1.WPF.DataGrid.DataGridCreatingRowEventArgs e) { if (rowCounter == 1) { e.Row.RowStyle = ApplyCellStyle() as Style; } rowCounter++; } public Style ApplyCellStyle() { string str = @"<Style xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:c1=""http://schemas.componentone.com/wpf/DataGrid"" TargetType=""c1:DataGridRowPresenter""> <Setter Property=""BorderThickness"" Value=""0""/> <Setter Property=""Template""> <Setter.Value> <ControlTemplate TargetType=""c1:DataGridRowPresenter"" > <Border BorderBrush=""Blue"" BorderThickness=""3""> <Grid x:Name=""Root"" Margin=""{TemplateBinding CellsAreaMargin}""> <VisualStateManager.VisualStateGroups> <VisualStateGroup x:Name=""ValidationStates""> <VisualState x:Name=""Valid""/> <VisualState x:Name=""InvalidUnfocused""> <Storyboard> <DoubleAnimationUsingKeyFrames Storyboard.TargetName=""Validation"" Storyboard.TargetProperty=""(UIElement.Opacity)"" Duration=""0""> <DiscreteDoubleKeyFrame KeyTime=""00:00:00"" Value=""1""/> </DoubleAnimationUsingKeyFrames> </Storyboard> </VisualState> <VisualState x:Name=""InvalidFocused"" > </VisualState> </VisualStateGroup> </VisualStateManager.VisualStateGroups> <Border x:Name=""BackgroundElement"" Background=""{TemplateBinding Background}""/> <Border x:Name=""UserBackground"" Background=""{TemplateBinding Background}""/> <Border x:Name=""Validation"" Background=""#2BFF0000"" Opacity=""0"" /> <c1:DataGridCellsPanel x:Name=""Cells""/> <Rectangle x:Name=""HorizontalGridLine"" Grid.Row=""1"" Height=""1"" Fill=""{TemplateBinding HorizontalGridLineBrush}"" Visibility=""{TemplateBinding HorizontalGridLineVisibility}"" Opacity=""{TemplateBinding HorizontalGridLineOpacity}"" VerticalAlignment=""Bottom""/> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style>"; return (Style)XamlReader.Parse(str); }Regards
Ashish| #
You must be logged in to reply to this topic.

