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 { get; set; } |
} |
public abstract class Visualitem { |
public object Parent { get; set; } |
} |
public class GridDataItem : Visualitem { |
public GridDataItem( string first, string middle, string last ) { |
this.FirstName = first; |
this.LastName = last; |
this.MiddleName = middle; |
} |
public string FirstName { get; set; } |
public string MiddleName { get; set; } |
public string LastName { get; set; } |
} |
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