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

Untyped Collection throws and exception on edit mode

3 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rogério
Top achievements
Rank 1
Rogério asked on 28 Apr 2009, 02:08 PM
Hello,

I've created an Untyped collection ou array of items to assign to a RadGridView. Everything works well on ReadOnly mode! If I set ReadOnly to false and double click the cell, an exception ("Object reference not set to an instance of an object ") if thrown on method GridViewCell.ShowEditor().

If I use System.Windows.Controls.Data.DataGrid it works fine! If I create a typed collection or list and assign to the grid it works fine!

It seams that RadGridView could not assign a CellEditor (at least a default/generic one) when there's no type defined on Collections!

Here is my code:
<UserControl x:Class="SilverlightApplication23.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"       
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"                 
    Width="400" Height="300">
    <Grid x:Name="LayoutRoot" Background="White">
        <StackPanel>
            <telerik:RadGridView IsReadOnly="False" x:Name="dgEntityTypes" AutoGenerateColumns="False">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn HeaderText="Name" DataMemberBinding="{Binding Name}" />
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
            <data:DataGrid x:Name="dgEntityTypes2" BorderBrush="Transparent" AutoGenerateColumns="False" IsReadOnly="False" CanUserResizeColumns="False">
                <data:DataGrid.Columns>
                    <data:DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"/>                                
                </data:DataGrid.Columns>
            </data:DataGrid>
        </StackPanel>
    </Grid>
</UserControl>

    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();            

            ObservableCollection<Object> mycol = new ObservableCollection<Object>();
            Test t1 = new Test();
            t1.Name = "aaa";
            t1.Id = "111";

            Test t2 = new Test();
            t2.Name = "aaa";
            t2.Id = "111";
            mycol.Add(t1);
            mycol.Add(t2);

            dgEntityTypes.ItemsSource = mycol;
            dgEntityTypes2.ItemsSource = mycol;
        }
    }
    public class Test
    {
        public string Name { set; get; }
        public string Id { set; get; }
    }

Is there any work-arround for this issue? This is a problem with a huge impact on our application because it's used a lot.

Thanks in advance!!

Regards,
Rogério

3 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Dobrev
Telerik team
answered on 29 Apr 2009, 11:42 AM
Hi Rogério,

You can use extension methods from System.Linq namespace:
dgEntityTypes.ItemsSource = mycol.Cast<Test>().ToList(); 

This way the grid will correctly pick up the collection's underlying type, which in your case is the Test class.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Rogério
Top achievements
Rank 1
answered on 29 Apr 2009, 11:58 AM
Hello Stefan,

This workaround works, but I'd appreciate to have this bug fixed on future releases.

Thanks.

Regards,
Rogério
0
Stefan Dobrev
Telerik team
answered on 29 Apr 2009, 01:38 PM
Hi Rogério,

I have already logged this bug in our backlog. Thanks for point it. I have updated your Telerik points.

Best wishes,
Stefan Dobrev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Rogério
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Rogério
Top achievements
Rank 1
Share this question
or