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

Using CellStyle

4 Answers 64 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Amige
Top achievements
Rank 1
Veteran
Amige asked on 06 Mar 2015, 03:05 AM
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

4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 06 Mar 2015, 11:48 AM
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.

 
0
Amige
Top achievements
Rank 1
Veteran
answered on 06 Mar 2015, 06:22 PM
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
0
Accepted
Dimitrina
Telerik team
answered on 09 Mar 2015, 01:53 PM
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.

 
0
Amige
Top achievements
Rank 1
Veteran
answered on 09 Mar 2015, 04:23 PM
Hello Dimitrina,

I'll check the documentation on UI Virtualization.

Thanks for your help.

Regards,

Alberto
Tags
GridView
Asked by
Amige
Top achievements
Rank 1
Veteran
Answers by
Dimitrina
Telerik team
Amige
Top achievements
Rank 1
Veteran
Share this question
or