private void listViewTabs_ItemDrag(object sender, ItemDragEventArgs e)
        {
            var listViewItem = e.Item as ListViewItem;

            if (listViewItem != null)
            {
                DragableListItem dragableListItem = _listViewDataSource.FirstOrDefault(x => x.Index == listViewItem.Index);
                if (dragableListItem != null)
                {
                    DoDragDrop(dragableListItem, DragDropEffects.Move);
                }
            }
        }
        private void listViewTabs_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.Label.Length <= MAX_LABEL_LENGTH && e.Label.Length >= MIN_LABEL_LENGTH)
            {
                DragableListItem listViewItem = _listViewDataSource.FirstOrDefault(x => x.Index == e.Item);
                if (listViewItem != null)
                {
                    listViewItem.Label = e.Label;
                }
                TabDataChanged = true;
                return;
            }
            string textboxMessage = $"Invalid label length. The tab label must be between {MIN_LABEL_LENGTH} and {MAX_LABEL_LENGTH} characters long";

            e.CancelEdit = true;
            MessageBox.Show(this, textboxMessage, "Unable to edit label", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        private void listViewTabs_DragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(DragableListItem)))
            {
                return;
            }
            if (listViewTabs.SelectedItems.Count == 0)
            {
                return;
            }

            Point        p = listViewTabs.PointToClient(MousePosition);
            ListViewItem liteViewItemClosestToDropPosition = GetClosestItemInRelationToDropPosition(listViewTabs, p);
            var          dragItem = e.Data.GetData(typeof(DragableListItem)) as DragableListItem;

            if (liteViewItemClosestToDropPosition == null || liteViewItemClosestToDropPosition.Index == dragItem.Index)
            {
                return;
            }

            int originalIndex = dragItem.Index;
            int newIndex      = liteViewItemClosestToDropPosition.Index;

            if (radioButtonSwitch.Checked)
            {
                DragableListItem listItem1 = _listViewDataSource.First(x => x.Index == newIndex);
                DragableListItem listItem2 = _listViewDataSource.First(x => x.Index == originalIndex);

                listItem1.Index = originalIndex;
                listItem2.Index = newIndex;
            }
            else
            {
                int  minIndex  = Math.Min(newIndex, originalIndex);
                int  maxIndex  = Math.Max(newIndex, originalIndex);
                bool leftShift = newIndex > originalIndex;

                if (leftShift)
                {
                    var itemsToShiftIndex = _listViewDataSource.Where(x => x.Index > minIndex && x.Index <= maxIndex).OrderBy(x => x.Index).ToList();
                    DragableListItem listViewItemToSwitch = _listViewDataSource.First(x => x.Index == minIndex);

                    foreach (DragableListItem listItem in itemsToShiftIndex)
                    {
                        listItem.Index = listItem.Index - 1;
                    }

                    listViewItemToSwitch.Index = maxIndex;
                }
                else
                {
                    var itemsToShiftIndex = _listViewDataSource.Where(x => x.Index >= minIndex && x.Index < maxIndex).OrderBy(x => x.Index).ToList();
                    DragableListItem listViewItemToSwitch = _listViewDataSource.First(x => x.Index == maxIndex);

                    foreach (DragableListItem listItem in itemsToShiftIndex)
                    {
                        listItem.Index = listItem.Index + 1;
                    }

                    listViewItemToSwitch.Index = minIndex;
                }
            }

            TabDataChanged = true;
            _listViewDataSource.Sort();
            LoadTabPageCollection();
        }