Skip to main content

RibbonBarCollectionBase<TOwner, TElement>

Namespace: Wisej.Web.Ext.RibbonBar

Assembly: Wisej.Web.Ext.RibbonBar (4.1.0.0)

Base implementation of the component collections managed in the RibbonBar control.

public abstract class RibbonBarCollectionBase<TOwner, TElement> : IList<TElement>, ICollection<TElement>, IEnumerable<TElement>, IEnumerable, IList, ICollection

Adding, inserting or removing elements updates the owner on the client automatically. Elements cannot be replaced using the indexer; remove the element and insert the new one instead.

Parameters​

NameDescription
TOwnerType of the component that owns the collection.
TElementType of the components stored in the collection.

Properties​

Instance member Count​

Int32: Returns the number of TElement items in the collection.

Instance member Item(index)​

TElement: Returns the TElement at the specified location.

Value: The TElement at the specified index.

Throws:

Example:

Iterating the pages in a RibbonBar by index:

for (int i = 0; i < this.ribbonBar1.Pages.Count; i++)
{
this.ribbonBar1.Pages[i].Enabled = (i == 0);
}

Methods​

Instance member Add(item)​

Adds the specified item to the collection.

ParameterTypeDescription
itemTElementThe TElement to add to the collection.

Example:

Adding a button to a group:

this.ribbonBarGroup1.Items.Add(new RibbonBarItemButton { Text = "Refresh", ImageSource = "icon-refresh" });

Instance member Clear()​

Removes all the items from the collection.

The removed items are not disposed. Use Clear to dispose them.

Example:

Removing all the items from a group to rebuild it:

this.ribbonBarGroup1.Items.Clear();

Instance member Clear(dispose)​

Removes and optionally disposes all the items from the collection.

ParameterTypeDescription
disposeBooleantrue to dispose the removed items; false to only remove them.

Example:

Removing and disposing all the groups in a page:

this.ribbonBarPage1.Groups.Clear(true);

Instance member Contains(item)​

Checks whether the specified item exists in the collection.

ParameterTypeDescription
itemTElementThe TElement to find in the collection.

Returns: Boolean. true if the specified item exists in the collection; otherwise, false.

Example:

Adding a page only if it's not already in the RibbonBar:

if (!this.ribbonBar1.Pages.Contains(this.pageReview))
this.ribbonBar1.Pages.Add(this.pageReview);

Instance member CopyTo(array, index)​

Copies all the items in the collection to the specified array starting at the specified index .

ParameterTypeDescription
arrayTElement[]The target array.
indexInt32The starting index in the target array.

Example:

Copying the items of a group to an array:

var items = new RibbonBarItem[this.ribbonBarGroup1.Items.Count];
this.ribbonBarGroup1.Items.CopyTo(items, 0);

Instance member GetEnumerator()​

Returns an IEnumerator to iterate the items in the collection.

Returns: IEnumerator<TElement>. An instance of IEnumerator.

Example:

Disabling all the items in a group:

foreach (var item in this.ribbonBarGroup1.Items)
{
item.Enabled = false;
}

Instance member IndexOf(item)​

Returns the position of the specified item in the collection.

ParameterTypeDescription
itemTElementThe TElement to find in the collection.

Returns: Int32. The index of the item or -1 if not found.

Example:

Inserting a new button right after an existing one:

var index = this.ribbonBarGroup1.Items.IndexOf(this.buttonCopy);
if (index > -1)
this.ribbonBarGroup1.Items.Insert(index + 1, new RibbonBarItemButton { Text = "Copy Format" });

Instance member Insert(index, item)​

Inserts the specified item in the collection at the specified index .

ParameterTypeDescription
indexInt32The position to insert the specified TElement at.
itemTElementThe TElement to insert in the collection.

Throws:

Example:

Inserting a page as the first tab:

this.ribbonBar1.Pages.Insert(0, new RibbonBarPage { Text = "Start" });

Protected member OnCollectionChanged(e)​

Fires the CollectionChanged event.

ParameterTypeDescription
eCollectionChangeEventArgsA CollectionChangeEventArgs that contains the event data.

Instance member Remove(item)​

Removes the specified TElement from the collection.

ParameterTypeDescription
itemTElementThe TElement to remove from the collection.

Returns: Boolean. true if the specified item has been removed from the collection; false if it was not found.

The removed item is not disposed. Call Dispose on the item instead to remove it and dispose it.

Example:

Removing a button from its group:

this.ribbonBarGroup1.Items.Remove(this.buttonMacros);

Instance member RemoveAt(index)​

Removes the TElement at the specified position.

ParameterTypeDescription
indexInt32The index of the TElement to remove from the collection.

The removed item is not disposed.

Throws:

Example:

Removing the last page of the RibbonBar:

var pages = this.ribbonBar1.Pages;
if (pages.Count > 0)
pages.RemoveAt(pages.Count - 1);

Events​

Instance member CollectionChanged​

CollectionChangeEventHandler Fired when the collection changes.