0

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

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by Sravanthi Ch
0

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

I need more information.

Edited by Mitja Bonca: n/a

0

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();
        }
0

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

0

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.

0

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]);
}

Edited by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.