/// <summary> /// Constructs a basic column /// </summary> /// <param name="name">Name of column, this can be used to identify the column across languages being used where caption will be different</param> /// <param name="caption">The caption used on the header.</param> /// <param name="width">Initial width of the column</param> public Column(string name, string caption, int width, ColumnItemValueAccessor columnItemValueAccessor) { if (name == null) { throw new ArgumentNullException("name"); } if (caption == null) { throw new ArgumentNullException("caption"); } if (width < 0) { throw new ArgumentOutOfRangeException("width"); } _name = name; _caption = caption; _width = width; _columnItemValueAccessor = columnItemValueAccessor; _comparitor = delegate(object x, object y) { object cellItemX = ColumnItemAccessor(x); object cellItemY = ColumnItemAccessor(y); IComparable comparer = cellItemX as IComparable; if (comparer == null) { string error = string.Format("Cell item for column '{0}' doesn't support comparing. You will need to supply a comparer by setting Column.Comparitor", Name); throw new NotSupportedException(error); } return(comparer.CompareTo(cellItemY)); }; _groupedComparitor = delegate(object x, object y) { if (x == y) { return(0); } if (x != null && y != null) { if (GroupItemAccessor(x) == GroupItemAccessor(y)) { return(0); } } return(_comparitor(x, y)); }; }
/// <summary> /// Constructs a basic column /// </summary> /// <param name="name">Name of column, this can be used to identify the column across languages being used where caption will be different</param> /// <param name="caption">The caption used on the header.</param> /// <param name="width">Initial width of the column</param> public Column( string name, string caption, int width, ColumnItemValueAccessor columnItemValueAccessor ) { if( name == null ) { throw new ArgumentNullException( "name" ); } if( caption == null ) { throw new ArgumentNullException( "caption" ); } if( width < 0 ) { throw new ArgumentOutOfRangeException( "width" ); } _name = name; _caption = caption; _width = width; _columnItemValueAccessor = columnItemValueAccessor; _comparitor = delegate( object x, object y ) { object cellItemX = ColumnItemAccessor( x ); object cellItemY = ColumnItemAccessor( y ); IComparable comparer = cellItemX as IComparable; if( comparer == null ) { string error = string.Format( "Cell item for column '{0}' doesn't support comparing. You will need to supply a comparer by setting Column.Comparitor", Name ); throw new NotSupportedException( error ); } return comparer.CompareTo( cellItemY ); }; _groupedComparitor = delegate( object x, object y ) { if( x == y ) { return 0; } if( x != null && y != null ) { if( GroupItemAccessor( x ) == GroupItemAccessor( y ) ) { return 0; } } return _comparitor( x, y ); }; }
/// <summary> /// Creates a copy of the given column /// </summary> /// <param name="columnToCopy"></param> public Column( Column columnToCopy ) { _name = columnToCopy._name; _comparitor = columnToCopy._comparitor; _caption = columnToCopy._caption; _width = columnToCopy._width; _sortOrder = columnToCopy._sortOrder; _groupSortOrder = columnToCopy._groupSortOrder; _isVisible = columnToCopy._isVisible; _isGrouped = columnToCopy._isGrouped; _columnItemValueAccessor = columnToCopy._columnItemValueAccessor; _groupItemValueAccessor = columnToCopy._groupItemValueAccessor; _groupedComparitor = columnToCopy._groupedComparitor; _headerIcon = columnToCopy.HeaderIcon; _isFixedWidth = columnToCopy.IsFixedWidth; _showHeaderSortArrow = columnToCopy.ShowHeaderSortArrow; _wrapText = columnToCopy.WrapText; }