ComponentFactory.Krypton.Ribbon.ViewLayoutRibbonGalleryItems.SyncChildren C# (CSharp) Method

SyncChildren() public method

public SyncChildren ( ) : void
return void
        public void SyncChildren()
        {
            int required = 0;
            int selectedIndex = _gallery.SelectedIndex;
            ImageList imageList = _gallery.ImageList;

            // Find out how many children we need
            if (imageList != null)
                required = _gallery.ImageList.Images.Count;

            // If we do not have enough already
            if (Count < required)
            {
                // Create and add the number extra needed
                int create = required - Count;
                for (int i = 0; i < create; i++)
                    Add(new ViewDrawRibbonGalleryItem(_gallery, _triple, this, _needPaint));
            }
            else if (Count > required)
            {
                // Destroy the extra ones no longer needed
                int remove = Count - required;
                for (int i = 0; i < remove; i++)
                    RemoveAt(0);
            }

            // Tell each item the image it should be displaying
            for (int i = 0; i < required; i++)
            {
                ViewDrawRibbonGalleryItem item = (ViewDrawRibbonGalleryItem)this[i];
                item.ImageList = imageList;
                item.ImageIndex = i;
                item.Checked = (selectedIndex == i);
            }
        }