private void OnClearItems(object sender, EventArgs e)
{
if ((_ribbonCluster != null) && (_ribbonCluster.Ribbon != null))
{
// Use a transaction to support undo/redo actions
DesignerTransaction transaction = _designerHost.CreateTransaction("KryptonRibbonGroupCluster ClearItems");
try
{
// Get access to the Items property
MemberDescriptor propertyItems = TypeDescriptor.GetProperties(_ribbonCluster)["Items"];
RaiseComponentChanging(propertyItems);
// Need access to host in order to delete a component
IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
// We need to remove all the buttons from the cluster group
for (int i = _ribbonCluster.Items.Count - 1; i >= 0; i--)
{
KryptonRibbonGroupItem item = _ribbonCluster.Items[i];
_ribbonCluster.Items.Remove(item);
host.DestroyComponent(item);
}
RaiseComponentChanged(propertyItems, null, null);
}
finally
{
// If we managed to create the transaction, then do it
if (transaction != null)
transaction.Commit();
}
}
}