コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            ListBox.ObjectCollection list = listBox1.Items;
            int n = list.Count;

            if (n == 0)
            {
                return;
            }

            int broj1 = rand.Next(n);

            MessageBox.Show(list[broj1].ToString(), "Izvučen je tim:");

            foreach (Control ctr in this.Controls)
            {
                if (ctr is Label)
                {
                    if (ctr.Name == "label" + (27 - n))
                    {
                        ctr.Text = list[broj1].ToString();
                    }
                }
            }
            list.RemoveAt(broj1);

            //     label27.Text = list.Count.ToString();
        }
コード例 #2
0
            private ListBox.ObjectCollection quicksort(ListBox.ObjectCollection list)
            {
                ListBox.ObjectCollection sorted = new ListBox.ObjectCollection(new ListBox());
                sorted.AddRange(list);

                if (sorted.Count <= 1)
                {
                    return(sorted);
                }

                int random = randomNumberGenerator.Next(0, sorted.Count - 1);

                string pivot = (string)list[random];

                sorted.RemoveAt(random);

                ListBox.ObjectCollection lessThan    = new ListBox.ObjectCollection(new ListBox());
                ListBox.ObjectCollection greaterThan = new ListBox.ObjectCollection(new ListBox());

                for (int i = 0; i < sorted.Count; ++i)
                {
                    sortItem(sorted[i], pivot, lessThan, greaterThan);
                }

                sorted = quicksort(lessThan);
                sorted.Add(pivot);
                sorted.AddRange(quicksort(greaterThan));

                return(sorted);
            }
コード例 #3
0
        public static ListBox.ObjectCollection TrimTo(this ListBox.ObjectCollection collection, int cnt)
        {
            int totalcnt = collection.Count;

            for (int i = 0; i < totalcnt - cnt; i++)
            {
                collection.RemoveAt(totalcnt - i - 1);
            }
            return(collection);
        }
コード例 #4
0
        private void reverse_btn_Click(object sender, EventArgs e)
        {
            ListBox lb = GetChildeControl <ListBox>(tc_Person.SelectedTab);

            ListBox.ObjectCollection items = lb.Items;

            lb.BeginUpdate();
            for (int i = 0, j = items.Count - 1; i < j; i++, j--)
            {
                object tempI = items[i];
                object tempJ = items[j];

                items.RemoveAt(j);
                items.RemoveAt(i);

                items.Insert(i, tempJ);
                items.Insert(j, tempI);
            }
            lb.EndUpdate();
        }
コード例 #5
0
 private void View_OnDeleteFigureButton_Click(object sender, int index)
 {
     if (index >= 0)
     {
         _figuresBuffer.RemoveAt(index);
         _outFigures.RemoveAt(index);
     }
     else
     {
         _view.ShowError(new Exception("Не выделена фигура в списке, не удалось удалить."));
     }
 }
コード例 #6
0
        public string UpdateTicketList(ListBox.ObjectCollection items)
        {
            int  firstTicket      = 0;
            bool firstTicketFound = false;
            int  lastTicket       = 0;

            // Examine the queue to determine which tickets are for the
            // current time slot. All tickets for the current time slot
            // are removed from the queue and the firstTicket and lastTicket
            // fields are set to the first and last ticket numbers.
            //
            while (ticketQueue.Count >= 1)
            {
                Ticket ticket = ticketQueue.Peek();
                if (ticket.TimeWindow.StartTime < DateTime.Now)
                {
                    ticketQueue.Dequeue();
                    if (!firstTicketFound)
                    {
                        firstTicket      = ticket.Number;
                        firstTicketFound = true;
                    }
                    lastTicket = ticket.Number;
                    items.RemoveAt(0);
                }
                else
                {
                    break;
                }
            }

            // Return message that indicates which ticket numbers may now enter.
            //
            if (!firstTicketFound)                 //No tickets currently served
            {
                return("");
            }
            else
            {
                if (firstTicket == lastTicket)     //One ticket currently served
                {
                    return(firstTicket.ToString());
                }
                else                               //More than one ticket currently served
                {
                    return(firstTicket.ToString() + " - " + lastTicket.ToString());
                }
            }
        }
コード例 #7
0
 public override void RemoveAt(int index)
 {
     _items.RemoveAt(index);
 }
コード例 #8
0
        void ToggleBranch(int index)
        {
            TreeNodeBase node = (TreeNodeBase)Items[index];

            if (!node.HasKids)
            {
                /*node.allkids = treeOwner.FetchKids(TokenObject, node);
                 * if(node.allkids.Count ==0)
                 * {
                 *      return;
                 * }*/
                return;
            }

            int count = Items.Count;

            if (node.IsExpanded)
            {
                index++;
                int          upTo = index;
                TreeNodeBase kid  = null;
                // eh, hopefully item access is cheap

                ListBox.ObjectCollection items = treeListBox.Items;

                while (upTo < count && (kid = (TreeNodeBase)items[upTo]).depth > node.depth)
                {
                    kid.IsExpanded = false;
                    upTo++;
                }

                int i, nodesInList = items.Count;
                int toRemove         = upTo - index;
                int costOfRemoveAt   = toRemove * (1 + nodesInList - upTo);
                int costOfRebuilding = 2 * nodesInList + 3 * (nodesInList - (upTo - index));

                if (costOfRemoveAt < costOfRebuilding)
                {
                    for (i = upTo; i-- > index;)
                    {
                        items.RemoveAt(i);
                    }
                }
                else
                {
                    object[] allNodes = new object[nodesInList - toRemove];
                    for (i = 0; i < index; i++)
                    {
                        allNodes[i] = items[i];
                    }
                    for (i = upTo; i < nodesInList; i++)
                    {
                        allNodes[i - toRemove] = items[i];
                    }

                    ReplaceContents(allNodes);
                }

                node.IsExpanded = false;
            }
            else
            {
                AddAfter(index, node);
                node.IsExpanded = true;
            }
        }
コード例 #9
0
ファイル: FrmMain.cs プロジェクト: kissbence2003/WFA210105
 private void BtnDeleteSelectedClick(object sender, EventArgs e)
 {
     collection.RemoveAt(lbx.SelectedIndex);
 }