Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not sure and this would have to be tested, but <a href="http://www.devx.com/dotnet/Article/8014/1954" rel="nofollow">this article makes me believe that what I am going to say is true.</a></p> <p>Basically, if you go by the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.drawitem.aspx" rel="nofollow">MSDN documentation</a>:</p> <blockquote> <p>Occurs when a visual aspect of an owner-drawn ListBox changes.</p> </blockquote> <p>So, this means that everytime an item is added, this event is called. Also, I think even when you perform certain drawing actions within this method, it will call itself (you might be able to avoid this using <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.control.suspendlayout.aspx" rel="nofollow">SuspendLayout</a> and <a href="http://msdn.microsoft.com/en-us/library/y53zat12.aspx" rel="nofollow">ResumeLayout</a> on the listbox while updating), but am not sure.</p> <p>Here is the kicker as far as I know it. Everytime this event is triggered, it is pretty much for every item in the list. (This might be useful in that you can de-color a previously selected item, so dont jump directly to what I am about to suggest without thinking it through). So, the DrawItemEventArgs has an index of the item being drawn. Using that, you can focus in on a specific item that you need to draw. That might help you from re-processing something that has already been processed (keep in mind the notes from the above article..copied below, about index being allowed to be -1).</p> <p>To visualize this process:</p> <pre><code>Add 1 item -&gt;DrawItem Add 2nd item-&gt;DrawItem -&gt;DrawItem Add 3rd item-&gt;DrawItem -&gt;DrawItem -&gt;DrawItem Add nth item-&gt;DrawItem * n </code></pre> <p>So, this actually results in a kind of <a href="http://en.wikipedia.org/wiki/Fibonacci_number" rel="nofollow">fibonacci type situation</a> (3 items resulted in 6 calls...5 would result in your 15 number), and you can see how the initial load could be cumbersome, and how adding a new item make for n calls to the method.</p> <p>From the article above:</p> <blockquote> <p><strong>The ListBox calls the DrawItem method repeatedly, for each item in its Items collection.</strong></p> <p>The DrawItemEventArgs argument to the DrawItem event handler exposes an Index property whose value is the index of the item to be drawn. Watch out! The system raises the DrawItem event with an index value of -1 when the Items collection is empty. When that happens you should call the DrawItemEventArgs.DrawBackground() and DrawFocusRectangle() methods and then exit. The purpose of raising the event is to let the control draw a focus rectangle so that users can tell it has the focus, even when there are no items present. The code traps for that condition, calls the two methods, and then exits the handler immediately</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload