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

Subclassing and binding

4 Answers 116 Views
GridView
This is a migrated thread and some comments may be shown as answers.
capsule
Top achievements
Rank 1
capsule asked on 18 Nov 2009, 06:34 PM

Hello,

I have recently upgraded to the latest Q3 release and have run into a problem that used to work with the Q2 binaries.  I have an object that I use to “collect” properties from multiple objects for displaying on a grid.  For instance, I have a person object with name properties, and an address object(collection) with its fields.  In a grid, I’d like to display the person’s name and their (primary) address.

I had a solution that worked well in the Q2 binaries, but since the upgrade my solution will no longer work as the item source seems to look at the base class, instead of the object being passed in. 

Here’s a boiled down example to illustrate my issue.   


Here's the class difinitions:
        public class Visualitems : List<Visualitem> {  
            object Parent { getset; }  
        }  
        public abstract class Visualitem {  
            public object Parent { getset; }  
        }  
        public class GridDataItem : Visualitem {  
            public GridDataItem( string first, string middle, string last ) {  
                this.FirstName = first;  
                this.LastName = last;  
                this.MiddleName = middle;  
            }  
            public string FirstName { getset; }  
            public string MiddleName { getset; }  
            public string LastName { getset; }  
        }  
 

Here's how I attempt to setup and populate the grid:
            Visualitems items = new Visualitems();  
            items.Add( new GridDataItem( "Jon""A""Smith" ) );  
            items.Add( new GridDataItem( "Tom""P""Jones" ) );  
            items.Add( new GridDataItem( "Ken""W""Adams" ) );  
            items.Add( new GridDataItem( "Kelly""C""Truman" ) );  
 
            Telerik.Windows.Controls.GridViewDataColumn gvc = new Telerik.Windows.Controls.GridViewDataColumn();  
            gvc.UniqueName = "FirstName";  
            gvc.Header = "First Name";  
            gvc.DataContext = "FirstName";  
            gvc.IsVisible = true;  
            gvc.Width = new Telerik.Windows.Controls.GridViewLength( 1, Telerik.Windows.Controls.GridViewLengthUnitType.Star );  
            grid.Columns.Add( gvc );  
              
            Binding binding = new Binding();  
            binding.Source = items;  
            binding.Mode = BindingMode.OneWay;  
            binding.BindsDirectlyToSource = true;  
 
            grid.DataContext = binding.Source;  
            grid.SetBinding( Telerik.Windows.Controls.RadGridView.ItemsSourceProperty, binding ); 

This will generate the error:  "Property with name FirstName cannot be found on type Visualitem"

Any guidance on this matter would be appreciated...

Thank you in advance for your time,

Craig

4 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 23 Nov 2009, 03:41 PM
Hello capsule,

Indeed with 2009.3.1103 version there are some issues with this scenario, but I still cannot get such exception. Maybe I'm doing something wrong. Can you provide me with more detailed information (what to change in my project) in order to get this exception.
I'm attaching my test application with latest internal build dlls, which works fine on my end. Let me know if it does not help.

All the best,
Nedyalko Nikolov
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
capsule
Top achievements
Rank 1
answered on 23 Nov 2009, 07:45 PM

Nedyalko,

Well, the good news is that when I applied the DLLs included with your sample to my project, the old functionality was restored and the grids displayed without error!  So that’s promising news for a future upgrade…

As for your inquiry regarding the error, when I changed references to the existing Q3 DLL’s, I was able to reproduce the error with the sample you provided.  I have a screen shot of my exception configuration attached.  Nothing special / additional was done to see the error.  

I’m using VS 2008 SP 1, running Windows 7, 64 bit

On a side note, from time to time, I will be presented with a file dialog box asking for a Telerik file for debugging.  I only mention it now, because it asked for PropertyPathDescriptor.cs, followed by another file, whose name I missed (something Data).  I’m not sure if that’s standard practice for your controls, but I thought I’d mention it anyway.  

Given that the latest files you provided seemed to work, if you have an expected date / timeframe for an internal build release or a service pack, I’d appreciate the info. 

Thanks for your time,

Craig

0
Accepted
Vlad
Telerik team
answered on 26 Nov 2009, 10:06 AM
Hi Craig,

The internal build will be published Tomorrow and the service pack is scheduled for first week of December.

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
capsule
Top achievements
Rank 1
answered on 30 Nov 2009, 05:16 PM
Thank you for the update, Vlad.
Tags
GridView
Asked by
capsule
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
capsule
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or