views:

220

answers:

1

Hi. I have an owner-drawn listbox control in my project. The problem is that sometimes the DrawItemEventArgs argument passed to my DrawItem event-handler has an Index property of "-1". It seems that this only happens when I scroll through the list box and then try to close my application; To avoid getting an exception I did something very unethical:

    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. If you need any extra info feel free to ask it. Thanks for your time and sharing your knowledge in advance.

~Phidelity

+1  A: 

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

dommer