Hi,

I need code to invert the selected items in list view.

Can any one help me out..

Thanks in advance for help..


Regards,

Sravanthi Ch

Recommended Answers

All 5 Replies

How to invert?
From last to 1st? By which column (items, or subItems)?

I need more information.

Hi, try this

private void button1_Click(object sender, EventArgs e)
        {
            for (int k = 0; k < listV.Items.Count; ++k)
            {
                listV.Items[k].Selected = !(listV.Items[k].Selected);
                
            }
            listV.Select();
        }

Hi, try this

private void button1_Click(object sender, EventArgs e)
        {
            for (int k = 0; k < listV.Items.Count; ++k)
            {
                listV.Items[k].Selected = !(listV.Items[k].Selected);
                
            }
            listV.Select();
        }

Hi,

I am not gettign the selected property in listV.Items[k].Selected..

Any how i got the solution for it..

Thanks for replying.

Regards,

Sravanhi Ch

Would you mind telling me exactly what would you like to invert? I have no exact clue now, what you would you like to have. Thx in advance.

Hi,

Here is the code i have used in my application.

Here i need to unselect the selected items and select the unselected item in a button click which means i need to invert the selected items in a list view.

// Storing the selected items in an int List

 List<int> _intList = new List<int>();
 for (int k = 0; k < MyListView.SelectedItems.Count; k++)
    _intList.Add(MyListView.Items.IndexOf(MyListView.SelectedItems[k]));

// Clearing the selected items

 MyListView.SelectedItems.Clear(); 

// Inverting
 for (int i = 0; i < MyListView.Items.Count; i++)
 {
 if (!_intList.Contains(i))
                    MyListView.SelectedItems.Add(MyListView.Items[i]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.