Hi,
Is it possible to have background color for MainColumn like this?(please see attached )
You can use the UltraListView.MainColumn.ItemAppearance.BackColor property to get something close to this, but the catch is that the color won't extend past the last item down to the bottom of the control.
An alternative approach is to use the IUIElementCreationFilter interface to add a custom UIElement that will draw a background for the whole area underneath the column's header. The following code sample demonstrates this approach:
AppearanceData appearanceData = new AppearanceData(); appearanceData.BackColor = Color.LightYellow; appearanceData.BorderColor = Color.Yellow; appearanceData.BorderColor2 = Color.White; this.ultraListView1.CreationFilter = new ColumnBackgroundCreationFilter( this.ultraListView1.MainColumn, appearanceData );
#region ColumnBackgroundCreationFilter /// <summary> /// IUIElementCreationFilter implementation which Handles the display of /// checkboxes for UltraListViewItems in Thumbnails mode. /// </summary> public class ColumnBackgroundCreationFilter : IUIElementCreationFilter { private UltraListViewColumnBase column = null; private AppearanceData appearanceData = new AppearanceData(); private ColumnUIElement columnElement = null;
public ColumnBackgroundCreationFilter( UltraListViewColumnBase column, AppearanceData appearanceData ) { if ( column == null ) throw new ArgumentNullException();
this.column = column; this.appearanceData = appearanceData.Clone(); }
private ColumnUIElement GetColumnUIElement( UIElement parent ) { // If the cached element is null, or has a different parent, // create a new instance, otherwise return the cached one. if ( this.columnElement == null || this.columnElement.Parent != parent ) this.columnElement = new ColumnUIElement( parent, this.column, ref this.appearanceData );
return this.columnElement; }
/// <summary> /// Gets/sets the AppearanceData that defines the appearance attributes /// of the element that represents the associated column. /// </summary> public AppearanceData AppearanceData { get { return this.appearanceData; } set { this.appearanceData = value; UltraListView listView = this.column.Control; UltraListViewUIElement controlElement = listView != null ? listView.UIElement : null; if ( controlElement != null ) controlElement.DirtyChildElements( true ); } }
#region IUIElementCreationFilter implementation
void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent) { UltraListView listView = this.column.Control; bool showGroups = listView != null ? listView.ShowGroups && listView.Groups.Count > 0 : false; UIElement containerElement = null; if ( showGroups ) containerElement = parent as UltraListViewGroupContainerUIElement; else containerElement = parent as UltraListViewItemContainerUIElement;
if ( containerElement != null ) { // Locate the column's header element, which we will use to define // the width of the column area. UltraListViewUIElement controlElement = containerElement.ControlElement as UltraListViewUIElement; UltraListViewColumnHeaderUIElement headerElement = controlElement.GetDescendant( typeof(UltraListViewColumnHeaderUIElement), this.column ) as UltraListViewColumnHeaderUIElement; if ( headerElement != null ) { // Get the rectangle that defines the column's bounds, i.e., // the area underneath the header. Rectangle clientArea = controlElement.RectInsideBorders; Rectangle headerRect = headerElement.Rect; Rectangle columnRect = headerRect; columnRect.Height = clientArea.Height - headerRect.Height; columnRect.Y = headerRect.Bottom;
// Create/extract a ColumnUIElement that we will use to // handle the drawing of the background and borders. ColumnUIElement columnElement = this.GetColumnUIElement( containerElement ); columnElement.Rect = columnRect;
// Insert the ColumnUIElement at position zero in the // ChildElements collection, so it draws before (i.e., // in the background of) the item elements. containerElement.ChildElements.Insert( 0, columnElement ); }
} }
bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent) { UltraListView listView = this.column.Control; bool showGroups = listView != null ? listView.ShowGroups && listView.Groups.Count > 0 : false; UIElement containerElement = null; if ( showGroups ) containerElement = parent as UltraListViewGroupContainerUIElement; else containerElement = parent as UltraListViewItemContainerUIElement;
// Try to find an existing ColumnUIElement from the "last" batch of UIElements, // so we can reduce object instantiation overhead. if ( containerElement != null ) this.columnElement = containerElement.GetDescendant( typeof(ColumnUIElement), this.column ) as ColumnUIElement;
return false; }
#endregion IUIElementCreationFilter implementation
#region ColumnUIElement class /// <summary> /// UIElement-derived class which is used to draw a column background. /// </summary> public class ColumnUIElement : UIElement { private AppearanceData appearanceData;
public ColumnUIElement( UIElement parent, UltraListViewColumnBase column, ref AppearanceData appearanceData ) : base( parent ) { this.PrimaryContext = column; this.appearanceData = appearanceData; }
/// <summary> /// Returns Border3DSide.Right so that only the right border is drawn. /// </summary> public override Border3DSide BorderSides { get { return Border3DSide.Right; } }
/// <summary> /// Returns UIElementBorderStyle.TwoColor so that we can have a two-color border. /// </summary> public override UIElementBorderStyle BorderStyle { get { return UIElementBorderStyle.TwoColor; } }
/// <summary> /// Initializes the AppearanceData that is used to draw this element. /// </summary> protected override void InitAppearance(ref AppearanceData appearance, ref AppearancePropFlags requestedProps) { AppearanceData.Merge( ref appearance, ref this.appearanceData, ref requestedProps ); } } #endregion ColumnUIElement class
} #endregion ColumnBackgroundCreationFilter