Esempio n. 1
0
        /// <summary>
        /// Moves the selected items from the origin to the destination.
        /// </summary>
        /// <param name="origin">The origin.</param>
        /// <param name="destination">The destination.</param>
        private static void moveItem(ListBox origin, ListBox destination)
        {
            //Create ArrayList of current items
            var originList = new ArrayList(origin.Items);

            //Create ArrayList of destination items
            var destinationList = new ArrayList(destination.Items);

            //Add selected items from origin listbox to destination list
            foreach (ListBoxItem item in origin.SelectedItems)
            {
                destinationList.Add(item);
            }

            //remove the selected items from the origin list
            foreach (var item in origin.SelectedItems)
            {
                originList.Remove(item);
            }

            //Comparer for sorting
            var comparer = new ListBoxItem();

            //Clear and repopulate origin Listbox sorted
            originList.Sort(comparer);
            origin.Items.Clear();
            origin.Items.AddRange(originList.ToArray());

            //Clear and repopulate destination Listbox sorted
            destinationList.Sort(comparer);
            destination.Items.Clear();
            destination.Items.AddRange(destinationList.ToArray());
        }
Esempio n. 2
0
        private void columnChooser_Load(object sender, EventArgs e)
        {
            //Set which ColumnHeader property to display
            lstCurrent.DisplayMember = "Text";
            lstAvailable.DisplayMember = "Text";

            foreach (ColumnHeader column in CurrentColumnsCollection)
            {
                if (string.IsNullOrEmpty(column.Text.Trim()))
                {
                    continue;
                }

                var item = new ListBoxItem {Text = column.Text, Column = column, DisplayIndex = column.DisplayIndex};

                if (column.Tag != null && column.Tag.ToString() == HiddenTag)
                {
                    lstAvailable.Items.Add(item);
                }
                else
                {
                    lstCurrent.Items.Add(item);
                }
            }
        }