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

ComboBoxColumn ArgumentException

1 Answer 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Franziska
Top achievements
Rank 1
Franziska asked on 01 Feb 2010, 12:13 PM
Hello

I have the setup as described below. I use the trial version binaries 2009.3.1314.35.
If you run this example and try to insert a new row by pressing the 'insert'-Key, then you result in an ArgumentException:
{"Property with specified name:  cannot be found on type: WpfApplication1.SimpleObject\r\nParameter name: propertyName"}.

The problem seems to be the 'SimpleObject'-Class. If you remove, or comment out, the ICustomTypeDescriptor interface from the class declaration then everything works ok.

Do you know this problem? Is there a solution or a work around?

Best regards,
Franziska

xaml:
<telerik:RadGridView x:Name="gridView"  
                                     ShowGroupPanel="False" IsFilteringAllowed="False" AutoGenerateColumns="False" 
                                     ItemsSource="{Binding PmodCollection}"  
                                     AddingNewDataItem="gridView_AddingNewDataItem" > 
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn Header="Test" DataMemberBinding="{Binding Test}" /> 
                <telerik:GridViewComboBoxColumn UniqueName="columnDescriptor" Header="Descriptor" 
                                                        DataMemberBinding="{Binding SimpleObject}" DisplayMemberPath="Descriptor" 
                                                        ItemsSource="{Binding SimpleObjChoiceList}"/> 
            </telerik:RadGridView.Columns> 
</telerik:RadGridView> 
Code behind:
public partial class Window1 : Window 
        public Window1() 
        { 
            InitializeComponent(); 
 
            this.DataContext = new DataContext(); 
        } 
 
        private void gridView_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e) 
        { 
            e.NewObject = new SimpleObjectPMod(); 
        } 
DataContext:
class DataContext 
        private List<SimpleObject> simpleObjs; 
        private ObservableCollection<SimpleObjectPMod> pmodCollection; 
 
        public DataContext() 
        { 
            simpleObjs = new List<SimpleObject>(); 
            simpleObjs.Add(new SimpleObject() { Descriptor = "bla" }); 
            simpleObjs.Add(new SimpleObject() { Descriptor = "fasel" }); 
 
            pmodCollection = new ObservableCollection<SimpleObjectPMod>(); 
        } 
 
        public List<SimpleObject> SimpleObjChoiceList 
        { 
            get { return simpleObjs; } 
        } 
 
        public ObservableCollection<SimpleObjectPMod> PmodCollection 
        { 
            get { return pmodCollection; } 
        } 
PMod:
class SimpleObjectPMod 
        public string Test 
        { 
            get; set; 
        } 
 
        public SimpleObject SimpleObject 
        { 
            get; set; 
        } 
Simple Object:
class SimpleObject : ICustomTypeDescriptor
{
        public string Descriptor
        {
            get; set;
        }

        #region Implementation of ICustomTypeDescriptor
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }
        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }
        public string GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, true);
        }
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }
        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }
        public PropertyDescriptorCollection GetProperties()
        {
            return GetProperties(null);
        }
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return TypeDescriptor.GetProperties(this, attributes, true);
        }
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
        #endregion
}

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 04 Feb 2010, 12:47 PM
Hi Franziska,

I've spotted two different issues with your example. Thank you for the detail information it was very helpful.

First issue is the way you bind ComboBoxColumn.ItemsSource. The assumption that this column data context is equal to the main window data context is a little bit incorrect. Actually this ItemsSource is provided to the parent GridViewCell, but DataContext of the cell is already related to its parent row business object. In other words this binding won't work. You can set ItemsSource in xaml with a StaticResource or you can use code behind syntax:

((GridViewComboBoxColumn) this.gridView.Columns["columnDescriptor"]).ItemsSource = ((DataContext) this.DataContext).SimpleObjChoiceList;

Second issue is related to RadGridView's support for ICustomTypeDescriptor interface. This definitely is a bug in our control. It is already fixed and will be available with the next latest internal build (Friday 5 Feb).
Sorry for the inconvenience caused.

P.S. I've updated your Telerik points accordingly.

Sincerely yours,
Nedyalko Nikolov
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Franziska
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or