This is a migrated thread and some comments may be shown as answers.

PreviewValidate and Dynmaic Style

3 Answers 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul Gallen
Top achievements
Rank 1
Paul Gallen asked on 12 Feb 2009, 12:00 PM
Hi

If there is an validation error on the editable cell, I set a style, in code, for that cell like so:-
 Private Sub gv1_PreviewValidate(ByVal sender As System.ObjectByVal e As Telerik.Windows.Controls.GridView.Cells.CellValidatingRoutedEventArgs)  
        If e.NewValue = String.Empty Then 
            e.ValidationResult = New Telerik.Windows.Controls.GridView.ValidationResult(FalseNothing)  
            DirectCast(DirectCast(e.OriginalSource, System.Object), Telerik.Windows.Controls.GridView.GridViewCell).Style = Me.FindResource("ContentControlStyleError")  
        Else 
            e.ValidationResult = New Telerik.Windows.Controls.GridView.ValidationResult(TrueNothing)  
            DirectCast(DirectCast(e.OriginalSource, System.Object), Telerik.Windows.Controls.GridView.GridViewCell).Style = Nothing 
        End If 

and the style is

 <Style x:Key="ContentControlStyleError" TargetType="{x:Type telerik:GridViewCell}">  
            <Setter Property="Template">  
                <Setter.Value> 
                    <ControlTemplate TargetType="{x:Type ContentControl}">  
                        <Border Width="110" Height="55" BorderThickness="2,2,2,2" CornerRadius="10,10,10,10" BorderBrush="#FF000000" RenderTransformOrigin="0.5,0.5">  
                            <Border.RenderTransform> 
                                <TransformGroup> 
                                    <ScaleTransform ScaleX="1" ScaleY="1"/>  
                                    <SkewTransform AngleX="0" AngleY="0"/>  
                                    <RotateTransform Angle="17.431"/>  
                                    <TranslateTransform X="0" Y="0"/>  
                                </TransformGroup> 
                            </Border.RenderTransform> 
                            <Border.Background> 
                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">  
                                    <GradientStop Color="#FF000000" Offset="0"/>  
                                    <GradientStop Color="#FFDC1D1D" Offset="1"/>  
                                </LinearGradientBrush> 
                            </Border.Background> 
                            <ContentPresenter   
                                        VerticalAlignment="Center"   
                                        HorizontalAlignment="Right"   
                                        Margin="0,0,10,0"   
                                        TextBlock.Foreground="White"  /> 
                        </Border> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 
now I know this style is awful, but it is the principle I am after.

When I set this style in code, the entire grid cells are no longer editable, also, if I scroll the grid so the offending cell is out of view, then scroll it back into view, the style has disappeared.

Any thoughts why this is happening?


Thanks

P

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 13 Feb 2009, 02:53 PM
Hello Paul,

Each GridViewCell needs two content presenters, named PART_ContentPresenter and PART_EditorPresenter in order to properly display the cell editor and content. Your template did not contain those presenters, hence the problem. Since the validation mechanisms of RadGridView are currently limited, I prepared a small workaround that achieves your requirement (excuse me for my ugly UI :) Please, let me know if the attached application does not work for you.

Greetings,
Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Paul Gallen
Top achievements
Rank 1
answered on 13 Feb 2009, 03:52 PM
Hi Hristov

This is just the ticket, Many thanks. Just a quick question. I do not think I would of ever using PART_xxx. Where can you locate this information. I am sure there must be quite a few PART_xxx in your controls. Can you point me in the right direction.


Once again thanks


P
0
Valeri Hristov
Telerik team
answered on 13 Feb 2009, 04:23 PM

Hello Paul,

Unfortunately we don't have a documentation article containing the list with all PART elements, grouped by class. However, I have a simple method that lists all controls with parts and their parts. I hope it helps:

public static void GetControlParts()
{
 var controlsWithParts =
  from type in typeof(RadGridView).Assembly.GetTypes()
  let parts = type.GetCustomAttributes(typeof(TemplatePartAttribute), true).Cast<TemplatePartAttribute>()
  where parts.Count() > 0
  select new
       {
        type.Name,
        Parts = from part in parts
          select new { part.Name, part.Type }
       };

 foreach (var control in controlsWithParts)
 {
  Console.WriteLine("Control:" + control.Name);
  foreach (var part in control.Parts)
  {
   Console.WriteLine("Part: {0}:{1}", part.Name, part.Type.FullName);
  }

  Console.WriteLine("*************************");
 }
}


Sincerely yours,

Valeri Hristov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Paul Gallen
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Paul Gallen
Top achievements
Rank 1
Share this question
or