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

EnableColumnVirtualization RowLoaded

4 Answers 146 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mily
Top achievements
Rank 1
Mily asked on 06 Nov 2009, 10:15 AM
Hi there,

We noticed e.Cells collection does not contain all the cells for the row when EnableColumnVirtualization is on (by default). Could you please confirm what the intended logic for e.Cells collection is after EnableColumnVirtualization feature was introduced - Does e.Cells contain only visible cells or it is a bug and it should contain all cells irrespectively.

Best Regards,

Milosz

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Nov 2009, 10:22 AM
Hello Milosz,

Indeed we can confirm this! When the column virtualization is on only visible cells will be part of row cells collection.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eugenio
Top achievements
Rank 1
answered on 06 Nov 2009, 12:58 PM

Hi,

I’ve set EnableColumnVirtualization property to false, but even so e.Cells does not contain the invisible columns. How do I get the invisible columns at the RowLoaded event?

Thanks in advance,

Eugênio

0
Jennifer
Top achievements
Rank 1
answered on 06 Nov 2009, 05:17 PM
I am interested in the above answer and I have a related question. I figure I need to use the RowLoaded event but I am not sure what to do here. I want to access a button in the row and make it collpased or visible depending on a value in the row.

Here is how I declared the button n the grid:

 <telerikGridView:GridViewColumn>
                                <telerikGridView:GridViewColumn.CellTemplate >
                                    <DataTemplate>
                                        <Button x:Name="btnPreview" Content="Preview"  Click="btnPreview_Click"  Visibility="Collapsed"/>
                                    </DataTemplate>
                                </telerikGridView:GridViewColumn.CellTemplate>
</telerikGridView:GridViewColumn>

I see how to access cells but not things inside a template like the above.

Thanks

0
Mily
Top achievements
Rank 1
answered on 06 Nov 2009, 09:13 PM
Hi Jeniffer,

There are at least two ways:

1. IValueConverter (reusable)

<UserControl x:Class="SilverlightApplication1.MainPage" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:converters="clr-namespace:SilverlightApplication1" 
             xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
             xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
  <Grid x:Name="LayoutRoot"
        <Grid.Resources> 
            <converters:PersonEditVisibilityConverter x:Key="personEditVisibilityConverter"/> 
        </Grid.Resources> 
            <telerikGrid:RadGridView ItemsSource="{Binding}"
            <telerikGrid:RadGridView.Columns> 
                <telerikGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/> 
                <telerikGrid:GridViewColumn> 
                    <telerikGrid:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <telerik:RadButton Content="Edit" 
                                               Visibility="{Binding Converter={StaticResource personEditVisibilityConverter}}" /> 
                        </DataTemplate> 
                    </telerikGrid:GridViewColumn.CellTemplate> 
                </telerikGrid:GridViewColumn> 
            </telerikGrid:RadGridView.Columns> 
        </telerikGrid:RadGridView> 
    </Grid> 
</UserControl> 


code behind: (generate some test data)

 
public partial class MainPage : UserControl 
    { 
        public MainPage() 
        { 
             
            InitializeComponent(); 
 
            var people = from i in Enumerable.Range(1, 10) 
                         select new Person() 
                         { 
                             Name = "Name " + i.ToString(), 
                             Age = i * 4, 
                             Id = i 
                         }; 
 
            DataContext = people; 
        } 
    } 
 

converter class:

 
public class PersonEditVisibilityConverter : IValueConverter 
    { 
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            var person = value as Person; 
 
            if (person == null
            { 
                throw new NotSupportedException(); 
            } 
 
            return person.Age < 10 ? Visibility.Collapsed : Visibility.Visible; 
        } 
 
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            throw new NotImplementedException(); 
        } 
    } 


2. Code behind (Make sure you switch off column virtualization):

<UserControl x:Class="SilverlightApplication1.MainPage" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
             xmlns:converters="clr-namespace:SilverlightApplication1" 
             xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" 
             xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
  <Grid x:Name="LayoutRoot"
             <telerikGrid:RadGridView ItemsSource="{Binding}" 
                                     RowLoaded="RadGridView_RowLoaded" 
                                     EnableColumnVirtualization="False"
            <telerikGrid:RadGridView.Columns> 
                <telerikGrid:GridViewDataColumn Header="Name" DataMemberBinding="{Binding Name}"/> 
                <telerikGrid:GridViewColumn UniqueName="ButtonColumn"
                    <telerikGrid:GridViewColumn.CellTemplate> 
                        <DataTemplate> 
                            <telerik:RadButton Content="Edit"/> 
                        </DataTemplate> 
                    </telerikGrid:GridViewColumn.CellTemplate> 
                </telerikGrid:GridViewColumn> 
            </telerikGrid:RadGridView.Columns> 
        </telerikGrid:RadGridView> 
    </Grid> 
</UserControl> 


code behind:

 
private void RadGridView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e) 
        { 
            var cell = e.Row.Cells.FirstOrDefault(c => c.Column.UniqueName == "ButtonColumn"); 
 
            if (cell != null
            { 
                var person = e.DataElement as Person; 
 
                if (person != null
                { 
                    var button = cell.ChildrenOfType<RadButton>().FirstOrDefault(); 
 
                    button.Visibility = person.Age < 10 ? Visibility.Collapsed : Visibility.Visible; 
                } 
            } 
        } 



Hope this helps!

Kind regards

Milosz
Tags
GridView
Asked by
Mily
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Eugenio
Top achievements
Rank 1
Jennifer
Top achievements
Rank 1
Mily
Top achievements
Rank 1
Share this question
or