Using CellStyle

5 posts, 1 answers
  1. Amige
    Amige avatar
    52 posts
    Member since:
    Dec 2013

    Posted 05 Mar 2015 Link to this post

    Hello,

    I have a RadGridView, it has 7 columns with boolean data. I want to disable each cell with a true value.

    I created a style and a converter, I add the style at runtime using the grid DataLoaded event:

    <Style x:Key="myCellStyle" TargetType="{x:Type telerik:GridViewCell}">
                <Setter Property="IsEnabled" Value="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource myConverter}}" />
            </Style>
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                GridViewCell cell = (GridViewCell)value;

                if(cell.Value == null)
                    return true;
                else
                    return (bool)cell.Value;
            }

    private void grid_DataLoaded(object sender, EventArgs e)
            {
                foreach (Telerik.Windows.Controls.GridViewColumn col in gridCheck.Columns)
                {
                        col.CellStyle = (Style)this.Resources["myCellStyle"];
                    
                }
            }

    In the converter I get a GridViewCell object in the value parameter, but the GridViewCell.Value property is always null.

    How can I pass the value of the cell to the converter?

    Thanks in advance,

    Alberto
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 06 Mar 2015 Link to this post

    Hi Alberto,

    In order to achieve the desired functionality, I can suggest you applying a CellStyleSelector instead. You can also check the CellStyleSelector online demo or the same one under the WPF Demos. 

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Amige
    Amige avatar
    52 posts
    Member since:
    Dec 2013

    Posted 06 Mar 2015 in reply to Dimitrina Link to this post

    Hello Dimitrina thanks for the information.

    I forgot to mention that I am using AutoGenerateColumns = true, in my example I mention that I had 7 columns but that can change, sometimes I could load more or less columns.

    I would like to use the same style for all the columns and just check if the value of the cell (regardless the column) is true then disable the cell and viceversa.

    Is there a way to accomplish that?

    Thanks,

    Alberto
  4. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Mar 2015 Link to this post

    Hi Alberto,

    Since RadGridView supports UI virtualization, its rows/cells are reused on scrolling. That is why it is not recommended to work with the visual elements directly. You can check our online documentation on UI Virtualization for a further reference. An approach relying on the bound properties (through applying a CellStyleSelector) would be a reliable one if you keep the row virtualization enabled.

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Amige
    Amige avatar
    52 posts
    Member since:
    Dec 2013

    Posted 09 Mar 2015 Link to this post

    Hello Dimitrina,

    I'll check the documentation on UI Virtualization.

    Thanks for your help.

    Regards,

    Alberto
Back to Top