Overriding the default style and refreshing the grid

4 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Jan 2014

    Posted 12 Feb 2014 Link to this post

    Hi - I have two problems I'm trying to solve:

    In my MVVM application, I have extended StyleSelector to my own EditStyleSelector. 

    In the xaml I have this: 
            <Grid.Resources>
                <styles:EditStyleSelector x:Key="MyStyleSelector" />
            </Grid.Resources>
    ...           
             <telerik:RadGridView x:Name="PermissionGridView" 
                                    IsReadOnly="True" 
                                    ItemsSource="{Binding ViewList}" 
                                    SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
                                    CanUserFreezeColumns="False" 
                                    RowIndicatorVisibility="Collapsed"
                                    RowDetailsVisibilityMode="Collapsed" 
                                    RowStyle="{x:Null}"
                                    AlternateRowStyle ="{x:Null}"
                                    AlternationCount ="0"
                                    AlternateRowBackground ="{x:Null}"
                                    RowStyleSelector="{StaticResource BastStyleSelector}"
                                    Margin="10,10">

    I have my own button for deleting rows from the gridview. I am not using the built-in controls.  When the Delete button is pressed, the row is marked as deleted in the gridview's underlying viewmodel, but not actually deleted. I just want the row marked for deletion to show up in a different colour. The EditStyleSelector class inspects the row item and returns a different style for each state of the row. Eg: Delete = Red, Edited = Blue, New Row = Green.

    This works, after a fashion, but I have two problems.

    Problem One: when alternating rows are enabled, my style is overwritten by the alternating row style. Apparently my style is being applied first, then the alternating row style. I can turn off alternating rows, making my style visible, but alternating rows are useful. I would like to have my style applied AFTER the alternating row style. Is this possible?

    Problem Two: I don't actually see my style change until I make some other change to the gridview that causes a re-validation(?). A column sort, or adding a new row will refresh the grid, making my style visible. How do I force the gridview to refresh/revalidate/reapply the style after my data changes?

    Thanks for any suggestions.


  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Feb 2014 Link to this post

    Hello,

    Generally if you apply a RowStyleSelector while having an alternation defined, then it will be applied only for the non-alternated Rows. If you would like to apply a StyleSelector for the alternated rows also, then you should additionally set the AlternateRowStyleSelector. 

    My suggestion is to not use alternation at all as it slows down the performance of RadGridView.

    As to your second problem, the style will be applied as soon as the user commit the row edit.

    Let me know if you have any additional questions.

    Regards,
    Didie
    Telerik

    Check out the new Telerik Platform - the only modular platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native apps. Register for the free online keynote and webinar to learn more about the Platform on Wednesday, February 12, 2014 at 11:00 a.m. ET (8:00 a.m. PT).

  3. DevCraft banner
  4. Michael
    Michael avatar
    2 posts
    Member since:
    Jan 2014

    Posted 18 Feb 2014 in reply to Dimitrina Link to this post

    We've fixed the row edits now showing up. The view model is an ObservableCollection of entity objects. The entity object class needed the [ImplementPropertyChanged] annotation.

    MyEntity.cs =====
    ...
        [ImplementPropertyChanged]
        public class MyEntity
        {
            public int AnAttribute { get; set; }
        }
    ...

    MyViewModel.cs ====
    ...
            public IList<MyEntity> ViewList { get; set; }
    ...
            public virtual void Initialize()
            {
                ViewList = new ObservableCollection<MyEntity>();
            }
    ...

    MyView.xaml ====
    ...
                <telerik:RadGridView x:Name="PermissionGridView" 
                                     IsReadOnly="True" 
                                     ItemsSource="{Binding ViewList}" 
                                     SelectedItem="{Binding SelectedItem, Mode=TwoWay}"                                                                    
                </telerik:RadGridView>
                <telerik:RadPropertyGrid x:Name="PropertyGrid1"
                                         Item="{Binding SelectedItem}" 
                                         DescriptionPanelVisibility="Collapsed"
                                         Margin="10">
                </telerik:RadPropertyGrid>
    ...


  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Feb 2014 Link to this post

    Hi,

    Thank you for sharing your solution with the community. You can also check this help article about editing an item outside RadGridView.

    Regards,
    Didie
    Telerik
Back to Top