Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The State of a listView item in the DrawItem event is wrong

Tags:

c#

.net

winforms

The question is in the code. Cannot understand why this is happening.

private void listView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
    // This works Ok
    if (e.Item.Selected)
    {
        // ...
    }

    // This works wrong!
    // e.State is always Selected! Why?
    if ((e.State & ListViewItemStates.Selected) != 0))
    {
        // ...
    }
}

Does someone have a similar problem?

like image 643
Zenya Avatar asked Mar 05 '10 09:03

Zenya


1 Answers

This looks like a known bug since about 2006, in evidence when the ListView.HideSelection property is set to FALSE.

The only workaround on file is to do what you've already done: use e.Item.Selected.

Here is a link to the bug report - looks like it's been relegated to low priority so far.

like image 180
Jared Avatar answered Oct 21 '22 13:10

Jared