Difference between revisions of "RibbonX Collections"
From Ribbon Commander Documentation
(→VBA) |
(→C#) |
||
Line 85: | Line 85: | ||
=== C# === | === C# === | ||
<syntaxhighlight lang="csharp" line> | <syntaxhighlight lang="csharp" line> | ||
+ | private void CollectionsCSSample() | ||
+ | { | ||
+ | // Create a new tab and play with its groups collection | ||
+ | rxTab myTab = new rxTab(); | ||
+ | |||
+ | // Print the number of groups in the tab (prints 0) | ||
+ | System.Diagnostics.Debug.WriteLine(myTab.groups.count); | ||
+ | |||
+ | // Create a new group and give it an id | ||
+ | rxGroup myGroup = new rxGroup(); | ||
+ | myGroup.id = "my_group"; | ||
+ | |||
+ | // Add the group to the tab's groups collection | ||
+ | myTab.groups.add(myGroup); | ||
+ | |||
+ | // Print the number of groups in the tab (prints 1) | ||
+ | System.Diagnostics.Debug.WriteLine(myTab.groups.count); | ||
+ | |||
+ | // Access an item by index | ||
+ | rxGroup myGroup2 = myTab.groups[1]; | ||
+ | |||
+ | // Access an item by id | ||
+ | rxGroup myGroup3 = myTab.groups["my_group"]; | ||
+ | |||
+ | // Remove an item by index | ||
+ | myTab.groups.remove(1); | ||
+ | |||
+ | // Print the number of groups in the tab (prints 0) | ||
+ | System.Diagnostics.Debug.WriteLine(myTab.groups.count); | ||
+ | |||
+ | // Add the item back and remove it by object reference | ||
+ | myTab.groups.add(myGroup); | ||
+ | myTab.groups.remove(myTab.groups["my_group"]); | ||
+ | |||
+ | // Print the number of groups in the tab (prints 0) | ||
+ | System.Diagnostics.Debug.WriteLine(myTab.groups.count); | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 16:09, 14 March 2013
This section is under construction. Please do not rely on any information it contains.
Contents
Description
The section describes the generic interface of Dynamic RibbonX collection and the operations that can be performed on them.
Properties
Property Name
|
Description
|
count | Read-only property; returns the count of items in a collection |
isEmpty | Read-only property; returns true if the control is empty |
isLive | Read-only property; returns true if the control is live |
item | (VBA/VB.NET-specific) Returns a reference to a collection member by index or id |
parent | The control's parent object |
Methods
Method Name
|
Description
|
add | Adds an item to the collection |
getItemIfExists | Returns a reference to a collection member by index or id. Does not throw if the index or id is out of bounds. |
remove | Removes an item from the collection (by index or item reference) |
removeAll | Removes all items from the collection |
operator[] | (C#-specific) Returns a reference to a collection member by index or id |
operator() | (VBA/VB.NET-specific) Returns are reference to a collection member by index or id |
Remarks
Examples
VBA
Public Sub ColectionsVBASample()
' Create a new group and play with its buttons collection
Dim myGroup As rxGroup
Set myGroup = New rxGroup
' Print number of buttons in the group (prints 0)
Debug.Print myGroup.Buttons.Count
' Create a new button and give it an id
Dim myButton As rxButton
Set myButton = New rxButton
myButton.ID = "my_button"
' Add the button to the group's buttons collection
myGroup.Buttons.Add myButton
' Print number of buttons in the group (prints 1)
Debug.Print myGroup.Buttons.Count
' Access an item by index
Dim myButton2 As rxButton
Set myButton2 = myGroup.Buttons.Item(1)
' Or alternatively
Set myButton2 = myGroup.Buttons(1)
' Access an item by id
Dim myButton3 As rxButton
Set myButton3 = myGroup.Buttons.Item("my_button")
' Or alternatively
Set myButton3 = myGroup.Buttons("my_button")
' Remove an item by index
myGroup.Buttons.Remove 1
' Print number of buttons in the group (prints 0)
Debug.Print myGroup.Buttons.Count
' Add the item back and remove it by object reference
myGroup.Buttons.Add myButton
' Get another ref to the button
Dim myButton4 As rxButton
Set myButton4 = myGroup.Buttons("my_button")
' Remove
myGroup.Buttons.Remove myButton4
' Print number of buttons in the group (prints 0)
Debug.Print myGroup.Buttons.Count
End Sub
C#
private void CollectionsCSSample()
{
// Create a new tab and play with its groups collection
rxTab myTab = new rxTab();
// Print the number of groups in the tab (prints 0)
System.Diagnostics.Debug.WriteLine(myTab.groups.count);
// Create a new group and give it an id
rxGroup myGroup = new rxGroup();
myGroup.id = "my_group";
// Add the group to the tab's groups collection
myTab.groups.add(myGroup);
// Print the number of groups in the tab (prints 1)
System.Diagnostics.Debug.WriteLine(myTab.groups.count);
// Access an item by index
rxGroup myGroup2 = myTab.groups[1];
// Access an item by id
rxGroup myGroup3 = myTab.groups["my_group"];
// Remove an item by index
myTab.groups.remove(1);
// Print the number of groups in the tab (prints 0)
System.Diagnostics.Debug.WriteLine(myTab.groups.count);
// Add the item back and remove it by object reference
myTab.groups.add(myGroup);
myTab.groups.remove(myTab.groups["my_group"]);
// Print the number of groups in the tab (prints 0)
System.Diagnostics.Debug.WriteLine(myTab.groups.count);
}