0
votes

Write now i can Copy items over between 2 listboxes. The problem is that when i copy the same items from listbox1 to listbox2 there is no problem, but when i delete the last item in listbox 2 it will delete all the others items before the last items because it is the same object. So i need to give my copied items and ID so when i copy an items over to listbox2 it will not be the same as the next item that will be copied to listbox2..

private void CopyItemOver_Click(object sender, EventArgs e)
        {

            foreach (ElementControl item in ElementListBox.SelectedItems)
            {
                if (item == null)
                    return;
                else
                {
                    SequenceListBox.ValueMember = item.ID.ToString();
                    item.ID++;
                    SequenceListBox.Items.Add(item);
                    elementNumber++;

                }
                SequenceListBox.SelectedIndex = SequenceListBox.Items.Count - 1;
                SequenceListBox.SelectedIndex = -1;
                Update();

            }
            if (ElementListBox.SelectedItems.Count <= 0)
            {
                return;
            }
            else
            {
                var objElement = SequenceListBox.Items[itemCounter] as ElementControl;
                if (SequenceListBox.Items.Count == 1)
                {
                    ListViewItem item = new ListViewItem(new[] { ElementListBox.SelectedItems.Count.ToString() + "  Elements moved to SequenceListBox", "Ready", GetTime() + "  " + elementNumber});
                    LogListView.Items.Add(item);
                }
                else
                {
                    ListViewItem item1 = new ListViewItem(new[] { ElementListBox.SelectedItems.Count.ToString() + "  Elements moved to SequenceListBox", "Ready", GetTime() + "  " + elementNumber });
                    LogListView.Items.Add(item1);
                }
            }
            LogListView.Items[LogListView.Items.Count - 1].EnsureVisible();
        }

Hope to make my question clear enough.

DuMaSexy.

1

1 Answers

0
votes

Instead of:

SequenceListBox.Items.Add(item);

use:

SequenceListBox.Items.Add(new ListItem() { Text = item.Text, Value = item.Value);