Difference between revisions of "RibbonX Collections"

From Ribbon Commander Documentation
Jump to: navigation, search
(Methods)
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Under Construction}}
 
 
 
 
== Description ==
 
== Description ==
The section describes the generic interface of Dynamic RibbonX collection and the operations that can be performed on them.
+
The section describes the generic interface of Ribbon Commander collection and the operations that can be performed on them.
  
  
Line 31: Line 28:
 
=== VBA ===
 
=== VBA ===
 
<syntaxhighlight lang="vb" line>
 
<syntaxhighlight lang="vb" line>
 +
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
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== 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>
  
 
=== VB.NET ===
 
=== VB.NET ===
 
<syntaxhighlight lang="vb" line>
 
<syntaxhighlight lang="vb" line>
 +
Private Sub CollectionsVBSample()
 +
 +
    ' Create a new group and play with its checkboxes collection
 +
    Dim myGroup As rxGroup = New rxGroup
 +
 +
    ' Print the number of checkboxes in the group (prints 0)
 +
    System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
 +
 +
    ' Create a new checkbox and give it an id
 +
    Dim myCheck As rxCheckBox = New rxCheckBox
 +
    myCheck.id = "my_checkbox"
 +
 +
    ' Add the checkbox to the group's checkboxes collection
 +
    myGroup.checkBoxes.add(myCheck)
 +
 +
    ' Print the number of checkboxes in the group (prints 1)
 +
    System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
 +
 +
    ' Access an item by index
 +
    Dim myCheck2 As rxCheckBox = myGroup.checkBoxes.item(1)
 +
    ' Or alternatively
 +
    myCheck = myGroup.checkBoxes(1)
 +
 +
    ' Access an item by id
 +
    Dim myCheck3 As rxCheckBox = myGroup.checkBoxes.item("my_checkbox")
 +
    ' Or alternatively
 +
    myCheck3 = myGroup.checkBoxes("my_checkbox")
 +
 +
    ' Remove an item by index
 +
    myGroup.checkBoxes.remove(1)
 +
 +
    ' Print the number of checkboxes in the group (prints 0)
 +
    System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
 +
 +
    ' Add the item back and remove it by object reference
 +
    myGroup.checkBoxes.add(myCheck)
 +
    myGroup.checkBoxes.remove(myGroup.checkBoxes("my_checkbox"))
 +
 +
    ' Print the number of checkboxes in the group (prints 0)
 +
    System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
 +
 +
End Sub
 
</syntaxhighlight>
 
</syntaxhighlight>
  

Latest revision as of 16:47, 30 September 2013

Description

The section describes the generic interface of Ribbon Commander 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

  1. Public Sub ColectionsVBASample()
  2.  
  3.     ' Create a new group and play with its buttons collection
  4.     Dim myGroup As rxGroup
  5.     Set myGroup = New rxGroup
  6.  
  7.     ' Print number of buttons in the group (prints 0)
  8.     Debug.Print myGroup.Buttons.Count
  9.  
  10.     ' Create a new button and give it an id
  11.     Dim myButton As rxButton
  12.     Set myButton = New rxButton
  13.     myButton.id = "my_button"
  14.  
  15.     ' Add the button to the group's buttons collection
  16.     myGroup.Buttons.Add myButton
  17.  
  18.     ' Print number of buttons in the group (prints 1)
  19.     Debug.Print myGroup.Buttons.Count
  20.  
  21.     ' Access an item by index
  22.     Dim myButton2 As rxButton
  23.     Set myButton2 = myGroup.Buttons.Item(1)
  24.     ' Or alternatively
  25.     Set myButton2 = myGroup.Buttons(1)
  26.  
  27.     ' Access an item by id
  28.     Dim myButton3 As rxButton
  29.     Set myButton3 = myGroup.Buttons.Item("my_button")
  30.     ' Or alternatively
  31.     Set myButton3 = myGroup.Buttons("my_button")
  32.  
  33.     ' Remove an item by index
  34.     myGroup.Buttons.Remove 1
  35.  
  36.     ' Print number of buttons in the group (prints 0)
  37.     Debug.Print myGroup.Buttons.Count
  38.  
  39.     ' Add the item back and remove it by object reference
  40.     myGroup.Buttons.Add myButton
  41.     ' Get another ref to the button
  42.     Dim myButton4 As rxButton
  43.     Set myButton4 = myGroup.Buttons("my_button")
  44.     ' Remove
  45.     myGroup.Buttons.Remove myButton4
  46.  
  47.     ' Print number of buttons in the group (prints 0)
  48.     Debug.Print myGroup.Buttons.Count
  49.  
  50. End Sub

C#

  1. private void CollectionsCSSample()
  2. {
  3.     // Create a new tab and play with its groups collection
  4.     rxTab myTab = new rxTab();
  5.  
  6.     // Print the number of groups in the tab (prints 0)
  7.     System.Diagnostics.Debug.WriteLine(myTab.groups.count);
  8.  
  9.     // Create a new group and give it an id
  10.     rxGroup myGroup = new rxGroup();
  11.     myGroup.id = "my_group";
  12.  
  13.     // Add the group to the tab's groups collection
  14.     myTab.groups.add(myGroup);
  15.  
  16.     // Print the number of groups in the tab (prints 1)
  17.     System.Diagnostics.Debug.WriteLine(myTab.groups.count);
  18.  
  19.     // Access an item by index
  20.     rxGroup myGroup2 = myTab.groups[1];
  21.  
  22.     // Access an item by id
  23.     rxGroup myGroup3 = myTab.groups["my_group"];
  24.  
  25.     // Remove an item by index
  26.     myTab.groups.remove(1);
  27.  
  28.     // Print the number of groups in the tab (prints 0)
  29.     System.Diagnostics.Debug.WriteLine(myTab.groups.count);
  30.  
  31.     // Add the item back and remove it by object reference
  32.     myTab.groups.add(myGroup);
  33.     myTab.groups.remove(myTab.groups["my_group"]);
  34.  
  35.     // Print the number of groups in the tab (prints 0)
  36.     System.Diagnostics.Debug.WriteLine(myTab.groups.count);
  37. }

VB.NET

  1. Private Sub CollectionsVBSample()
  2.  
  3.     ' Create a new group and play with its checkboxes collection
  4.     Dim myGroup As rxGroup = New rxGroup
  5.  
  6.     ' Print the number of checkboxes in the group (prints 0)
  7.     System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
  8.  
  9.     ' Create a new checkbox and give it an id
  10.     Dim myCheck As rxCheckBox = New rxCheckBox
  11.     myCheck.id = "my_checkbox"
  12.  
  13.     ' Add the checkbox to the group's checkboxes collection
  14.     myGroup.checkBoxes.add(myCheck)
  15.  
  16.     ' Print the number of checkboxes in the group (prints 1)
  17.     System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
  18.  
  19.     ' Access an item by index
  20.     Dim myCheck2 As rxCheckBox = myGroup.checkBoxes.item(1)
  21.     ' Or alternatively
  22.     myCheck = myGroup.checkBoxes(1)
  23.  
  24.     ' Access an item by id
  25.     Dim myCheck3 As rxCheckBox = myGroup.checkBoxes.item("my_checkbox")
  26.     ' Or alternatively
  27.     myCheck3 = myGroup.checkBoxes("my_checkbox")
  28.  
  29.     ' Remove an item by index
  30.     myGroup.checkBoxes.remove(1)
  31.  
  32.     ' Print the number of checkboxes in the group (prints 0)
  33.     System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
  34.  
  35.     ' Add the item back and remove it by object reference
  36.     myGroup.checkBoxes.add(myCheck)
  37.     myGroup.checkBoxes.remove(myGroup.checkBoxes("my_checkbox"))
  38.  
  39.     ' Print the number of checkboxes in the group (prints 0)
  40.     System.Diagnostics.Debug.WriteLine(myGroup.checkBoxes.count)
  41.  
  42. End Sub

C++

  1.