Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
550 views
in Technique[技术] by (71.8m points)

binding - Transfer items with properties from ListBox to another C#

I am currently developing a program to create images catalogue in PowerPoint. Long story short, the UI is organized to have 2 listboxes : Listbox1 (lst_itemList in the code below) is populated with the item list extracted from the source (excel file) Listbox2 is populated with only the items the user selects from ListBox1. Both ListBox have DataSource bind to a List.

Now, i have created a class called Item with some properties, and a List to contain them all. ListBox1 is bind to that List.

And here i have a problem: i have managed to transfer one Item at the time, but it is mandatory to allow the user to transfer more than 1 Item per time.

ctlItem.catalogList is la List that belong to a class called Catalog. It serves the purpose to collec all those Items that are going to be in the catalog when the user is done selecting them.

Here the code of the Item class:

    class Item
    {
        public string itemName { get; set; }
        public string itemCode { get; set; }
        public string itemColor { get; set; }
        public string itemSize { get; set; }
        public string itemPrice { get; set; }
        public string itemImage { get; set; }
        public bool isInCatalog { get; set; }


        public string displayItem
        {
            get
            {
                return string.Format("{0},{1}",itemName, itemCode);
            }
        }
    }

Here the code i wrote for the button "transfer":

private void bnt_addItemCatalog_Click(object sender, EventArgs e)
        {
            Item i = (Item)lst_itemList.SelectedItem;

            if (i.isInCatalog != true)
            {
                i.isInCatalog = true;
                ctlItem.catalogList.Add(i);
                catalogBinding.ResetBindings(false);
            }
            else
            {
                MessageBox.Show(i.itemName + "is already added to the catalog item List");
            }
        }

How i can add all the selected Item in ListBox1 to the ctlItem.catalogList ?

Thanks for your help and yout time.

question from:https://stackoverflow.com/questions/66049827/transfer-items-with-properties-from-listbox-to-another-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...