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.
- C#
- VB.NET
public abstract class RibbonBarCollectionBase<TOwner, TElement> : IList<TElement>, ICollection<TElement>, IEnumerable<TElement>, IEnumerable, IList, ICollection
Public MustInherit Class RibbonBarCollectionBase(Of TOwner, TElement)
Inherits IList(Of TElement)
Implements ICollection(Of TElement), IEnumerable(Of 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
| Name | Description |
|---|---|
| TOwner | Type of the component that owns the collection. |
| TElement | Type of the components stored in the collection. |
Properties
Count
Int32: Returns the number of TElement items in the collection.
Item(index)
TElement: Returns the TElement at the specified location.
Value: The TElement at the specified index.
Throws:
- NotSupportedException Cannot assign a TElement item.
- ArgumentOutOfRangeException index is less than 0 or greater than or equal to Count.
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
Add(item)
Adds the specified item to the collection.
| Parameter | Type | Description |
|---|---|---|
| item | TElement | The TElement to add to the collection. |
Example:
Adding a button to a group:
this.ribbonBarGroup1.Items.Add(new RibbonBarItemButton { Text = "Refresh", ImageSource = "icon-refresh" });
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();
Clear(dispose)
Removes and optionally disposes all the items from the collection.
| Parameter | Type | Description |
|---|---|---|
| dispose | Boolean | true 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);
Contains(item)
Checks whether the specified item exists in the collection.
| Parameter | Type | Description |
|---|---|---|
| item | TElement | The 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);
CopyTo(array, index)
Copies all the items in the collection to the specified array starting at the specified index .
| Parameter | Type | Description |
|---|---|---|
| array | TElement[] | The target array. |
| index | Int32 | The 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);
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;
}
IndexOf(item)
Returns the position of the specified item in the collection.
| Parameter | Type | Description |
|---|---|---|
| item | TElement | The 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" });
Insert(index, item)
Inserts the specified item in the collection at the specified index .
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The position to insert the specified TElement at. |
| item | TElement | The TElement to insert in the collection. |
Throws:
- ArgumentOutOfRangeException index is less than 0 or greater than Count.
Example:
Inserting a page as the first tab:
this.ribbonBar1.Pages.Insert(0, new RibbonBarPage { Text = "Start" });
OnCollectionChanged(e)
Fires the CollectionChanged event.
| Parameter | Type | Description |
|---|---|---|
| e | CollectionChangeEventArgs | A CollectionChangeEventArgs that contains the event data. |
Remove(item)
Removes the specified TElement from the collection.
| Parameter | Type | Description |
|---|---|---|
| item | TElement | The 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);
RemoveAt(index)
Removes the TElement at the specified position.
| Parameter | Type | Description |
|---|---|---|
| index | Int32 | The index of the TElement to remove from the collection. |
The removed item is not disposed.
Throws:
- ArgumentOutOfRangeException index is less than 0 or greater than or equal to Count.
Example:
Removing the last page of the RibbonBar:
var pages = this.ribbonBar1.Pages;
if (pages.Count > 0)
pages.RemoveAt(pages.Count - 1);
Events
CollectionChanged
CollectionChangeEventHandler Fired when the collection changes.