views:

285

answers:

2

hi all, how can show the listView.Items on Form2 in a ComboBox on Form1 and i want to use all data (subitems) from the selected Item

how can i do that? please make it easy to understand :)

thank you in advance

+1  A: 
Form1.comboBox.Items.AddRange(
    Form2.listView.Items.Cast<ListViewItem>().Select(a => a.Text));

This will simply copy the text of the ListViewItem to the combo box.

For all subitems, it gets a bit more complex:

Form1.comboBox.Items.AddRange(
    Form2.listView.Items.Cast<ListViewItem>().Select(
    a => string.Join(", ", a.SubItems
        .Cast<System.Windows.Forms.ListViewItem.ListViewSubItem>()
        .Select(s => s.Text).ToArray())).ToArray());

This uses LINQ to get an array of text values from the subitems of each item to be joined together with ", ", and adds each concatenated string list to the ComboBox

Codesleuth
A: 

Hi Codesleuth, can you take a look at this one: http://stackoverflow.com/questions/2752522/load-a-settings-settings-into-listview

Thanks

clefranc