4

I have an owner-drawn listbox control.

The problem is that sometimes the DrawItemEventArgs argument passed to my DrawItem event-handler has an Index property of "-1". This is my unethical fix:

private void lstBox_DrawItem(object sender, DrawItemEventArgs e)
{
    if (e.Index >= 0)
    {
        handler implementation
    }
}

I'd like to know what normally causes a negative index to be passed to the handler.

Rizier123
  • 58,877
  • 16
  • 101
  • 156
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76

1 Answers1

2

This may be when the listbox is empty, but receives the focus - e.g. if the list is cleared on closing.

dommer
  • 19,610
  • 14
  • 75
  • 137