private static PropertyInfo GetCollectionPropertyInfoFor <TItem, TPropertyCollectionItem>( Expressions.Expression <Func <TItem, IEnumerable <TPropertyCollectionItem> > > propertyExpression) { if (propertyExpression == null) { throw new ArgumentNullException("propertyExpression"); } var memberExp = propertyExpression.Body as Expressions.MemberExpression; if (memberExp == null) { throw new ArgumentNullException("propertyExpression"); } var propInfo = memberExp.Member as PropertyInfo; if (propInfo == null) { throw new ArgumentNullException("propertyExpression"); } if (!propInfo.DeclaringType.IsAssignableFrom(typeof(TItem))) { throw new ArgumentException("propertyExpression"); } return(propInfo); }
private void ReinitializeColumns() { Expressions.Expression<Func<Item, IEnumerable<Int32>>> exp = obj => obj.MyColumns; this.dataGrid.RegenerateColumns(exp, this.Items); }
public static void RegenerateColumns <TItem, TPropertyCollectionItem>( this DataGrid dataGrid, Expressions.Expression <Func <TItem, IEnumerable <TPropertyCollectionItem> > > propertyExpression, IEnumerable <TItem> items) { RegenerateColumns <TItem, TPropertyCollectionItem>(dataGrid, propertyExpression, items, (index) => String.Format("Column - {0}", index)); }
public static void RegenerateColumns <TItem, TPropertyCollectionItem>( this DataGrid dataGrid, Expressions.Expression <Func <TItem, IEnumerable <TPropertyCollectionItem> > > collectionPropertyExpression, IEnumerable <TItem> items, Func <Int32, String> formatHeader) { if (dataGrid == null) { throw new ArgumentNullException("dataGrid"); } if (collectionPropertyExpression == null) { throw new ArgumentNullException("propertyExpression"); } if (items == null) { throw new ArgumentNullException("items"); } if (formatHeader == null) { throw new ArgumentNullException("formatHeader"); } var collectionPropInfo = GetCollectionPropertyInfoFor <TItem, TPropertyCollectionItem>(collectionPropertyExpression); var propertyName = collectionPropInfo.Name; var getCount = GetCountGetter <TItem, TPropertyCollectionItem>( collectionPropertyExpression.Compile(), collectionPropInfo); // Remove old autocolumns dataGrid.RemoveAutoGeneratedColumns(propertyName); Int32 maxColumnsAdded = 0; // Create new columns foreach (var item in items) { GenerateColumnsForItem(dataGrid, item, getCount, formatHeader, propertyName, ref maxColumnsAdded); } }