C# – The type or namespace name ‘List Item’ could not be found


I am making a code to move the elements of a list box up and down. For that, I have made two buttons to move the element up (Move Up button) and down (Move Down button). Here is my code:

if (m_lbOPFfiles.SelectedIndex != m_lbOPFfiles.Items.Count && m_lbOPFfiles.SelectedIndex != -1)
            ListItem item = m_lbOPFfiles.SelectedItem;
            int index = m_lbOPFfiles.SelectedIndex;
            lstResdetails.Items.Insert(index + 1, item);

Now I am getting the namespace error for ListItem. Can anyone help me rectify it?

Best Solution

Well, you haven't said what type of application you're writing - Windows Forms? ASP.NET? WPF? Assuming it's ASP.NET, you need:

using System.Web.UI.WebControls;

at the top of your code. If it's WPF you might want:

using System.Windows.Documents;

EDIT: If it's Windows Forms then there isn't a ListItem class. ListBox.SelectedItem returns object, not ListItem. What aspect of a ListItem type would you want to use with the ListBox? (I'm assuming you're using a ListBox.) You can add items to ListBox.Items just as objects.