0

だから私は現在、リストボックス内の各項目にタイマーを付ける必要があるプログラムに取り組んでいます。それは機能していますが、どの項目も選択できません。できる方法はありますかアイテムを選択するだけでなく、リスト ボックス内の各アイテムにタイマーを表示しますか?

アップデート:

アイテムを新しいリストボックスに追加するとき、私が持っているコードは次のとおりです:

private void btnSchedule_Click(object sender, EventArgs e)
        {
            try
            {
                string name = lsbScheduled.SelectedItem.ToString();// saves the selected item to a string
                string newItem = (moveItem(name));//calls the method and passes the variable to it
                tmrCheckedIn.Enabled = true;
                tmrCheckedIn.Start();
                newItem += "      " + "00:00:00";
                lsbScheduled.Items.Remove(name);// removes the item from the list
                lsbCheckedIn.Items.Add(newItem); //adds the item to the list          
            }
            catch (NullReferenceException)
            {
            }
        }
here is my code for the tick event: 

 private void tmrCheckedIn_Tick(object sender, EventArgs e)
    {
        int count = lsbCheckedIn.Items.Count;

        for (int i = 0; i < count; i++)
        {
            string item = lsbCheckedIn.Items[i].ToString();
            string[] line = item.Split();
            string time = line[8];

            Time oldTime = new Time();
            oldTime.StartTime = time;

            lsbCheckedIn.Items.Remove(item);
            string newTime = string.Format(line[0] + " " + line[1] + " " +line[2] + "      " + "{0:c}", oldTime.EndTime);
            lsbCheckedIn.Items.Add(newTime);


            oldTime = null;

        }

    }

and here is my class that I use to increase the timer:
 public class Time
    {
        private int seconds, minutes, hours;
        string startTime, endTime;

       public Time()
        {
            seconds = 00;
            minutes = 00;
            hours = 00;
            startTime = " ";
            endTime = "";
        }

        public string StartTime
        {
            set { startTime = value;
            CalcNewTime();
            }
            get { return startTime; }
        }

        public string EndTime
        {
            set { endTime = value; }
            get { return endTime; }
        }

        public int Hours
        {
            set { hours = value; }
            get { return hours; }
        }

        public int Minutes
        {
            set { minutes = value; }
            get { return minutes; }
        }

        public int Second
        {
            set { seconds = value; }
            get { return seconds; }
        }

        private void CalcNewTime()
        {
            const int LIMIT = 6, CONVERT = 10;

            string[] divisions = startTime.Split(':');
            hours = Convert.ToInt32(divisions[0]);
            minutes = Convert.ToInt32(divisions[1]);
            seconds = Convert.ToInt32(divisions[2]);

            int hoursTens = hours / CONVERT;
            int hoursOnes = hours % CONVERT;
            int minutesTens = minutes / CONVERT;
            int minuteOnes = minutes % CONVERT;

            seconds += 1;
            int secondTens = seconds / CONVERT;
            int secondOnes = seconds % CONVERT;



            if (secondTens >= LIMIT)
            {
                secondTens = 0;
                secondOnes = 0;
                minutes += 1;

                minutesTens = Minutes / CONVERT;
                minuteOnes = minutes % CONVERT;
                if (minutesTens >= LIMIT)
                {
                    minutesTens = 0;
                    minuteOnes = 0;
                    hours += 1;

                    hoursTens = hours / CONVERT;
                    hoursOnes = Hours % CONVERT;
                }
            }
            endTime = Convert.ToString(hoursTens + hoursOnes + ":" + minutesTens + minuteOnes + ":" + secondTens + secondOnes);
        }

    }

ツールボックスから選択できるタイマーを使用して、Visual Studio 2010 im を使用して Windows フォーム アプリケーションをプログラミングします。リスト ボックスの項目を選択できるようにする必要がありますが、リスト ボックスの項目を常に追加および削除しているため、現在は選択できます。リストボックスに表示される時間を上げたいのですが、リストボックスの項目を選択できるようにするためにも必要です。

4

1 に答える 1

1

あなたの問題は、リストボックスからアイテムを削除してから、新しいアイテムを追加していることです。これが、アイテムが選択されたままにならない理由です。代わりに、アイテムを交換してください。

lsbCheckedIn.Items[i] = newTime;
于 2012-12-27T14:40:30.140 に答える