NewRowStyle problem

7 posts, 0 answers
  1. danijels
    danijels avatar
    6 posts
    Member since:
    May 2010

    Posted 31 May 2010 Link to this post

    Hi

    So I have a gridview control and some buttons that should add a new row to the grid. However, each button should add a row with a different setup (some columns should be disabled/invisible).

    So, my understanding is that I have to set up a few things in Grid.Resources, that being a control template with a target type and a setup and also a Style with a target type and a setter to set the temlate to the mentioned control template. First off, does this really have to be like this? Seems to me a bit too complex having to set up two different resources, one linking to another, per variation.

    Anyway, I've done this like so (simplified content):
    <ControlTemplate x:Key="Template1" TargetType="telerik:GridViewNewRow"
      <StackPanel Orientation="Horizontal"
         <TextBox Text="{Binding Code1}" /> 
      </StackPanel> 
    </ControlTemplate> 
    <ControlTemplate x:Key="Template2" TargetType="telerik:GridViewNewRow"
      <StackPanel Orientation="Horizontal"
         <TextBox Text="{Binding Code2}" /> 
      </StackPanel> 
    </ControlTemplate> 
    <Style x:Key="RowStyle1" TargetType="telerik:GridViewNewRow"
       <Setter Property="Template" Value="{StaticResource Template1}" /> 
    </Style> 
    <Style x:Key="RowStyle2" TargetType="telerik:GridViewNewRow"
       <Setter Property="Template" Value="{StaticResource Template2}" /> 
    </Style> 
    Then, on each buttons Click event I just add
    radGrid.NewRowStyle = (Style) LayoutRoot.Resources["RowStyle1"]; 
     
    (or whatever "Key" I need) before adding something to the ItemsSource observable collection. However, this doesn't seem to be enough and rows are always created the same. Is there any other way I should do it in order to create rows (and render existing ones) in different layouts?

    Thank you
  2. danijels
    danijels avatar
    6 posts
    Member since:
    May 2010

    Posted 02 Jun 2010 Link to this post

    Anyone has any tips on this one, please?

    Thank you
  3. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 04 Jun 2010 Link to this post

    Hi danijels,

    I have tested your case and the styles are being applied as expected. From your post it is a bit hard to identify what are you trying to accomplish. Could you please send me the real scenario you are having so I can be of assistance?

    All the best,
    Kalin Milanov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  4. danijels
    danijels avatar
    6 posts
    Member since:
    May 2010

    Posted 04 Jun 2010 Link to this post

    Kalin,

    Thank you for your reply. I have now created a new solution and I'll paste the code here as I am not allowed to attached a zip file to the thread. The example is simple enough. It should fire up the grid, bind it to ObservableCollection<Employee> and populate the source with some data. The issue is when inserting new rows with the buttons. Each button sets NewRowStyle to its own template and then adds an object to the data source. However, while I would expect new rows to obey the styling, they look the same regardless. I would like a row to look like the pre-populated ones when clicking on "Add", while clicking on "Add predefined" should create a new row with a single dropdown control spanning over all columns.

    Hope this is possible.

    First, xaml:
    <UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/datagrid"   
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"      
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"      
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        x:Class="RadControlsSilverlightApp1.MainPage"     
        xmlns:telc="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls"
        <Grid x:Name="LayoutRoot"
            <Grid.Resources> 
                <Style x:Key="buttonStyle" TargetType="telerik:RadButton"
                    <Setter Property="ClickMode" Value="Release" /> 
                </Style> 
                <ControlTemplate x:Key="PredefinedAnswerTemplate" TargetType="telerik:GridViewNewRow"
                    <StackPanel Orientation="Horizontal"
                        <ComboBox x:Name="cbRole"
                            <ComboBoxItem x:Name="Manager" x:Uid="1"></ComboBoxItem> 
                            <ComboBoxItem x:Name="Employee" x:Uid="2"></ComboBoxItem> 
                            <ComboBoxItem x:Name="Temp" x:Uid="3"></ComboBoxItem> 
                        </ComboBox> 
                    </StackPanel> 
                </ControlTemplate> 
                <ControlTemplate x:Key="StandardAnswerTemplate" TargetType="telerik:GridViewNewRow"
                    <StackPanel Orientation="Horizontal"
                        <TextBox Text="Predefined" /> 
                    </StackPanel> 
                </ControlTemplate> 
                <Style x:Key="pdRowStyle" TargetType="telerik:GridViewNewRow"
                    <Setter Property="Template" Value="{StaticResource PredefinedAnswerTemplate}" /> 
                </Style> 
                <Style x:Key="RowStyle" TargetType="telerik:GridViewNewRow"
                    <Setter Property="Template" Value="{StaticResource StandardAnswerTemplate}" /> 
                </Style> 
            </Grid.Resources> 
            <telerik:RadGridView x:Name="Answers" ShowGroupPanel="False" AutoGenerateColumns="True" VerticalAlignment="Center" NewRowStyle="{StaticResource pdRowStyle}" /> 
            <StackPanel Orientation="Horizontal" Height="20" VerticalAlignment="Top"
                <telc:RadButton Style="{StaticResource buttonStyle}" Content="Add" x:Name="newanswer" Click="NewanswerClick" /> 
                <telc:RadButton Style="{StaticResource buttonStyle}" Content="Add predefined" x:Name="newpd" Click="NewpredefClick" /> 
            </StackPanel> 
        </Grid> 
    </UserControl> 
     

    And the .cs:
    using System; 
    using System.Collections.ObjectModel; 
    using System.Windows; 
    using System.Windows.Controls; 
     
    namespace RadControlsSilverlightApp1 
        public partial class MainPage : UserControl 
        { 
            private readonly ObservableCollection<Employee> Employees; 
            public MainPage() 
            { 
                Employees = new ObservableCollection<Employee>(); 
                InitializeComponent(); 
                Answers.ItemsSource = Employees; 
                Answers.DataContext = Employees; 
                InitAnswers(); 
            } 
     
            void InitAnswers() 
            { 
                for (int i = 0; i < 10; i++) 
                { 
                    Employees.Add(new Employee 
                                    { 
                                        Email = "email" + i + "@email.com"
                                        FirstName = "Name" + i, 
                                        LastName = "Lastname" + i, 
                                        Phone = "332233" + i,  
                                        Role = "2" 
                                    }); 
                } 
            } 
     
            private void NewanswerClick(object sender, RoutedEventArgs e) 
            { 
                Answers.NewRowStyle = (Style)LayoutRoot.Resources["RowStyle"]; 
                NewClick(); 
            } 
     
            private void NewpredefClick(object sender, RoutedEventArgs e) 
            { 
                Answers.NewRowStyle = (Style)LayoutRoot.Resources["pdRowStyle"]; 
                NewClick(); 
            } 
            private void NewClick() 
            { 
                var item = Activator.CreateInstance(typeof(Employee)); 
                Employees.Add((Employee) item); 
                Answers.ScrollIntoView(item, null); 
            } 
        } 
     
        public class Employee 
        { 
            public string FirstName { getset; } 
            public string LastName { getset; } 
            public string Phone { getset; } 
            public string Email { getset; } 
            public string Role { getset; } 
        } 
     

  5. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 10 Jun 2010 Link to this post

    Hi Danijels,

    Thank you for the code sample. By the looks of it seems there is a difference of your understanding of the "new" row and ours. The "new" row is the one which appears on top of the grid and can be used to add new data. The new row can be shown via setting the ShowInsertRow="True" (a poor naming on our part which we will fix) and is affected by the NewRowStyle and is of type GridViewNewRow. 

    The ones which appear on the bottom are the same as any other row and they are affected by the RowStyle property and are of type GridViewRow.

    That being said I have modified your sample (attached to this reply) to show the GridViewNewRow and the templates are being applied as expected. Please review it and let me know if this is what you are looking for.

    Regards,
    Kalin Milanov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  6. danijels
    danijels avatar
    6 posts
    Member since:
    May 2010

    Posted 15 Jun 2010 Link to this post

    Thank you for clearing that up, Kalin.

    It was a bit poor naming, but I see the challenge. Anyway, am I to assume that what I'm looking for is not achievable, and if not, is there any indication that this might be something to look out for in the near future?

    Thanks again.
  7. Kalin Milanov
    Admin
    Kalin Milanov avatar
    447 posts

    Posted 18 Jun 2010 Link to this post

    Hi danijels,

    You are right. At this point what you are looking for is not achievable. That being said we could think of a way to make the new row at the bottom more visible or provide a way for users to customize it, though I cannot provide you with any estimate on this.

    I am truly sorry if this is causing you any inconveniences.

    Regards,
    Kalin Milanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top