Reputation: 93
I am just trying to add a selected item from a ComboBox to a ListBox, like this,
lboProveedoresSeleccionados.Items.Add(new ListBoxItem
(comboBox1.SelectedValue, comboBox1.SelectedText));
But i am getting this error "The type or namespace name 'ListBoxItem' could not be found (are you missing a using directive or an assembly reference?)", despite the fact that i have a reference already
using System.Windows.Controls;
Any idea? I know that i can just add the text, but i'm interested in have both, the values and the descriptions.
Upvotes: 1
Views: 3583
Reputation: 8551
Since this is a Windows Forms project, you can't use the WPF System.Windows.Controls.ListBoxItem
. But note that ListBox.Items
is an ObjectCollection
, not specifically a List<string>
or somesuch. It will accept any type of object and display the result of calling ToString()
on it. So you could make a class with the data you need and add instances of that class to the ListBox
.
Alternatively, if you want to use, e.g., some property of the object instead of ToString()
, you can use the DataSource
property and set the ListBox's
DisplayMember
and ValueMember
.
Upvotes: 4