简体   繁体   中英

C# moving item between listboxes no button

Is there a simple way to move Items between two text boxes without using a button. I am using C# (in Winforms). I have been trying something like this so that when a new item is clicked on the list it is immediately added to the other list then removed. Is there a way to keep the order of all of the items the same when moving them between the two lists? All of the other postings of similar questions selected/highlighted multiple items and then clicked a button to move them. I am hoping to immediately move any item that is clicked. I was trying to make two versions of the callback below for each listbox to move the items back and forth as an example to hopefully clarify my question.

private void features_SelectedIndexChanged(object sender, EventArgs e)
{
    unfeatures.Items.Add(features.SelectedItem);
    features.Items.Remove(features.SelectedItem);
}
        private void features_Click(object sender, EventArgs e)
    {
        if (features.SelectedIndex != -1)
        {
            unfeatures.Items.Add(features.SelectedItem);
            features.Items.Remove(features.SelectedItem);
        }
    }

Make sure you add the if statement so it does not crash. Run it when the listbox(named features in this case), is clicked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM