Alex Konnen
Alex Konnen

Reputation: 747

C# ListView SelectAll selection color

I am trying to set all items of a ListView as selected, using

foreach (ListViewItem item in this.m_lvFiles.Items)
{
    item.Selected = true;
}

and this works. However the listbox looks as Select All, programatically (all items' background color is white). If I select the items manually, the background color is blue, as in the second image (Select All, manually).

HideSelection=False, FullRowSelection=True, MultiSelect=True.

Question: is there a way to bring programmatically selected items like if they were selected manually?

Or is there a bug in ListView?

Upvotes: 2

Views: 459

Answers (2)

Nestoraj
Nestoraj

Reputation: 762

There is a related question about it that might help you:

Here

public static void SetItemState(ListView list, int itemIndex, int mask, int value) {
    LVITEM lvItem = new LVITEM();
    lvItem.stateMask = mask;
    lvItem.state = value;
    SendMessageLVItem(list.Handle, LVM_SETITEMSTATE, itemIndex, ref lvItem);
}

I hope it helps you

Upvotes: 2

denvercoder9
denvercoder9

Reputation: 811

Depending on where the focus is for your application, the selection may not show up as "blue". Setting the focus back to the list view after selecting each item will make each item's background 'blue':

m_lvFiles.Focus();

Assuming this is a win forms app...

Upvotes: 3

Related Questions