Hi ,
I am new to Wpf, EntityFramework and Telerik,
but i am trying to do the following :
I have a generic gridwindow ( telerik grid ) , that doesnt know what data it will display at compile time.
The grid is set to autogenerate the columns once it get a collection of data.
The data is a observable collection of EF Entities.
In the AutoGeneratingColumn event, I intercept each column.
columns of type Collection are skipped over,
columns of type String, Datetime or primitive types are shown.
I would like to replace the single columns to other Entities by n columns for their own primitive values.
So if i have a Entity Customer with a Property Address.
My grid would show by default :
Customer fields with binding path : Name, FirstName etc.
Address fields with binding path : Address.City, Address.Zip etc. all on the same row.
the code :
the Event :
In the load data method :
PS : i also tried doing the add of the new column in the event itsself, but it seemed Icky , and gave a cryptic error.
Any comments ?? it seems to be working most of the time . ( the embedded Entity isnt always loaded, even if the linq statment is always the same )
No real problems with it atm, so forum prob not the place to post this, but it wasnt working yet, when i started writing :)
I am new to Wpf, EntityFramework and Telerik,
but i am trying to do the following :
I have a generic gridwindow ( telerik grid ) , that doesnt know what data it will display at compile time.
The grid is set to autogenerate the columns once it get a collection of data.
The data is a observable collection of EF Entities.
In the AutoGeneratingColumn event, I intercept each column.
columns of type Collection are skipped over,
columns of type String, Datetime or primitive types are shown.
I would like to replace the single columns to other Entities by n columns for their own primitive values.
So if i have a Entity Customer with a Property Address.
My grid would show by default :
Customer fields with binding path : Name, FirstName etc.
Address fields with binding path : Address.City, Address.Zip etc. all on the same row.
the code :
the Event :
Telerik.Windows.Controls.GridViewBoundColumnBase c = gvc as Telerik.Windows.Controls.GridViewBoundColumnBase;
if ((!c.DataType.FullName.StartsWith("Afda.Model.TrackableCollection"))
&& (!c.DataType.FullName.StartsWith("Afda.Model.Obj")))
{
foreach (System.Reflection.PropertyInfo pi2 in c.DataType.GetProperties())
{
if (pi2.PropertyType.BaseType.IsValueType || pi2.PropertyType.FullName.Equals("System.String") || pi2.PropertyType.FullName.Equals("System.DateTime")
|| pi2.PropertyType.BaseType.FullName.Equals("System.ValueType"))
{
Telerik.Windows.Controls.GridViewDataColumn newColumn = new Telerik.Windows.Controls.GridViewDataColumn();
newColumn.Width = c.ActualWidth;
newColumn.DisplayIndex = c.DisplayIndex;
String s = c.DataMemberBinding.Path.Path + "." + pi2.Name;
newColumn.DataMemberBinding = new Binding(s);
newColumn.DataType = pi2.PropertyType;
newColumn.DataFormatString = c.DataFormatString;
newColumn.TextAlignment = c.TextAlignment;
newColumn.Header = s;
newColumn.Name = s;
newColumn.UniqueName = s;
newColumn.Footer = c.Footer;
newColumn.IsVisible = true;
colsToAdd.Add(newColumn);
}
}
gvc.IsVisible = false;
In the load data method :
try
{
DataGrid.ItemsSource = data;
}
catch { }
foreach (Telerik.Windows.Controls.GridViewDataColumn c in colsToAdd) {
if (!DataGrid.Columns.Contains(c)) {
DataGrid.Columns.Add(c);
}
}
PS : i also tried doing the add of the new column in the event itsself, but it seemed Icky , and gave a cryptic error.
Any comments ?? it seems to be working most of the time . ( the embedded Entity isnt always loaded, even if the linq statment is always the same )
No real problems with it atm, so forum prob not the place to post this, but it wasnt working yet, when i started writing :)