简体   繁体   中英

How do you take the contents of a combo box and add them to an array?

I've seen a lot about adding the contents of an Array to a ComboBox , but not the other way around. I would like to take the contents of a ComboBox add them to an Array to be sent to another method for processing.

I've already got the .Items.Count to determine the size of the Array , but I can't figure out how to cycle through the items in the ComboBox .

From looking at your comments on your question you probably want this:

var arr = ingredientComboBox.Items.Cast<Object>()
          .Select(item => item.ToString()).ToArray();
   string[] items = new string[currentComboBox.Items.Count];

   for(int i = 0; i < currentComboBox.Items.Count; i++)
   {
       items[i] = currentComboBox.Items[i].ToString();
   }

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