private void ShowItems()
        {
            Bitmap b = new Bitmap(pictureBox_DropDown.Image);

            b.RotateFlip(RotateFlipType.Rotate180FlipNone);
            pictureBox_DropDown.Image = b;

            if (!showData)
            {
                int ownIndex   = panel.Controls.IndexOfKey(Name);
                int childIndex = panel.Controls.GetChildIndex(panel.Controls[ownIndex]);

                childItem = new ShowDataItems(_data, _description, this.Size, this);


                panel.Controls.Add(childItem);
                panel.Controls.SetChildIndex(panel.Controls[panel.Controls.Count - 1], childIndex + 1);

                childItem.UpdateItems();


                showData = true;
            }
            else
            {
                int ownIndex = panel.Controls.IndexOfKey(Name);
                panel.Controls.RemoveAt(ownIndex + 1);

                showData = false;
            }
        }
        private void ChangeVisibilityOrder()
        {
            int mode = dataCollection.Schedule;

            if (showData)
            {
                int           ownIndex = panel.Controls.IndexOfKey(Name);
                ShowDataItems d        = (ShowDataItems)panel.Controls[ownIndex + 1];

                switch (mode)
                {
                case 0:
                    OrderVisible   = true;
                    d.OrderVisible = true;
                    break;

                case 1:
                    OrderVisible   = false;
                    d.OrderVisible = false;
                    break;

                case 2:
                    OrderVisible   = false;
                    d.OrderVisible = false;
                    break;
                }
            }
            else
            {
                switch (mode)
                {
                case 0:
                    OrderVisible = true;
                    break;

                case 1:
                    OrderVisible = false;
                    break;

                case 2:
                    OrderVisible = false;
                    break;
                }
            }
        }
        public Item_ShowDataItems(Data data, int _order, int Width, ShowDataItems child, CustomDataCollectionItem root)
        {
            InitializeComponent();
            //ItemWidth = 50;
            _width   = child.panel.Width;
            Order    = _order;
            ItemData = data;

            childItem = child;
            rootItem  = root;

            SetColor();

            TextField.Text = data.Name;
            SetHeight();

            oderField.Text = Order.ToString();

            fl = child.panel;
            oderField.SelectAll();
            oderField.SelectionAlignment = HorizontalAlignment.Center;
        }
        private void cpc_flowLayoutPanel_collection_Resize(object sender, EventArgs e)
        {
            int width;

            if (cpc_flowLayoutPanel_collection.Controls.Count > 0)
            {
                for (int i = 0; i < cpc_flowLayoutPanel_collection.Controls.Count; i++)
                {
                    if (cpc_flowLayoutPanel_collection.Controls[i].Name == "Show")
                    {
                        width = cpc_flowLayoutPanel_collection.Size.Width - (gap + 7);
                        ShowDataItems d = (ShowDataItems)cpc_flowLayoutPanel_collection.Controls[i];
                        d.ItemWidth = width;
                    }

                    width = cpc_flowLayoutPanel_collection.Size.Width - gap;
                    Size s = cpc_flowLayoutPanel_collection.Controls[i].Size;
                    s.Width = width;
                    cpc_flowLayoutPanel_collection.Controls[i].Size = s;
                    Thread.Sleep(1);
                }
            }
        }
        public Item_ShowDataItems(CustomDataCollectionItem root, ShowDataItems child, String description, int Width)
        {
            InitializeComponent();

            this.Pointer = -1;

            //ItemWidth = Width;
            _width    = child.panel.Width;
            rootItem  = root;
            childItem = child;

            SetColor();

            _Order         = -1;
            TextField.Text = description;
            SetHeight();

            oderField.Text = Order.ToString();

            itemPanel = child.panel;
            oderField.SelectAll();
            oderField.SelectionAlignment = HorizontalAlignment.Center;
        }
 private void toolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (showData)
     {
         int           ownIndex = panel.Controls.IndexOfKey(Name);
         ShowDataItems d        = (ShowDataItems)panel.Controls[ownIndex + 1];
         if (OrderVisible)
         {
             //toolStripMenuItem1.Text = "In order";
             d.OrderVisible          = false;
             OrderVisible            = false;
             dataCollection.Schedule = 1;
         }
         else
         {
             //toolStripMenuItem1.Text = "Choose random item";
             d.OrderVisible          = true;
             OrderVisible            = true;
             dataCollection.Schedule = 0;
         }
     }
     else
     {
         if (OrderVisible)
         {
             // toolStripMenuItem1.Text = "In order";
             OrderVisible            = false;
             dataCollection.Schedule = 1;
         }
         else
         {
             //toolStripMenuItem1.Text = "Choose random item";
             OrderVisible            = true;
             dataCollection.Schedule = 0;
         }
     }
 }
        private async void ShowItems2()
        {
            Bitmap b = new Bitmap(pictureBox_DropDown.Image);

            b.RotateFlip(RotateFlipType.Rotate180FlipNone);
            pictureBox_DropDown.Image = b;

            if (!showData)
            {
                int ownIndex   = panel.Controls.IndexOfKey(Name);
                int childIndex = panel.Controls.GetChildIndex(panel.Controls[ownIndex]);

                childItem = new ShowDataItems(_data, _description, this.Size, this);

                var progress = new Progress <string>(s => panel.Controls.Add(childItem));
                await Task.Factory.StartNew(() => SecondThreadConcern.LongWork(progress),
                                            TaskCreationOptions.LongRunning);

                var progress2 = new Progress <string>(s => panel.Controls.SetChildIndex(panel.Controls[panel.Controls.Count - 1], childIndex + 1));
                await Task.Factory.StartNew(() => SecondThreadConcern.LongWork(progress2),
                                            TaskCreationOptions.LongRunning);


                // panel.Controls.Add(childItem);
                // panel.Controls.SetChildIndex(panel.Controls[panel.Controls.Count - 1], childIndex + 1);

                showData = true;
            }
            else
            {
                int ownIndex = panel.Controls.IndexOfKey(Name);
                panel.Controls.RemoveAt(ownIndex + 1);

                showData = false;
            }
        }