Two questions on DrawItem event - CSharp

This is a discussion on Two questions on DrawItem event - CSharp ; Just two questions that I'd like answered to complete my mental picture. 1. Why do I need to set the DrawMode property in order to get the DrawItem event raised. In other events, I just name the event-handler and then ...

+ Reply to Thread
Results 1 to 2 of 2

Two questions on DrawItem event

  1. Default Two questions on DrawItem event

    Just two questions that I'd like answered to complete my mental
    picture.

    1. Why do I need to set the DrawMode property in order to get the
    DrawItem event raised. In other events, I just name the event-handler
    and then write it, and the event is raised. (In VB, I just had to
    write it, which still seems better). But for this one event, I have
    to flag the fact that I want it raised. Any reason?

    2. If I add the first items to a listbox in the form's Load event, I
    get a call to DrawItem for each addition, and I can use e.Index to see
    if it is the first, second, or third item. But if I add the first
    items elsewhere, eg, in response to a button click, I first get a
    series of calls to DrawItem in which e.Index = -1. Any reason?

    Dom


  2. Default Re: Two questions on DrawItem event

    On Fri, 03 Aug 2007 16:34:47 +0200, Dom <dolivastro> wrote:

    > Just two questions that I'd like answered to complete my mental
    > picture.
    >
    > 1. Why do I need to set the DrawMode property in order to get the
    > DrawItem event raised. In other events, I just name the event-handler
    > and then write it, and the event is raised. (In VB, I just had to
    > write it, which still seems better). But for this one event, I have
    > to flag the fact that I want it raised. Any reason?
    >


    Setting DrawMode tells the Control not to draw itself, which would lead to blank lines unless you handle the DrawItem event. Not sure how it ishandled in VB, but VB does a lot of stuff behind the scenes that isn't being done in C#, which in my opinion is very good.

    > 2. If I add the first items to a listbox in the form's Load event, I
    > get a call to DrawItem for each addition, and I can use e.Index to see
    > if it is the first, second, or third item. But if I add the first
    > items elsewhere, eg, in response to a button click, I first get a
    > series of calls to DrawItem in which e.Index = -1. Any reason?
    >
    > Dom
    >
    >


    My guess is, since the Control hasn't drawn its controls yet, there are fewer events necessary when you change the Control's datasource in the Load event. Whenever you do it later on, everything needs to be redrawn.As for the -1, i'm not sure.

    e.Index = -1 will be passed if the Control hasn't got a selection, which is handy if you want to write custom text like "Please select a value".

    --
    Happy coding!
    Morten Wennevik [C# MVP]

+ Reply to Thread

Similar Threads

  1. Drawing tabs in ListBox.DrawItem event
    By Application Development in forum DOTNET
    Replies: 1
    Last Post: 09-27-2007, 12:30 PM
  2. SMTP OnArrival transport event sinks - a couple of (maybe dumb) questions
    By Application Development in forum Microsoft Exchange
    Replies: 1
    Last Post: 09-03-2004, 09:06 AM
  3. NEED HELP!!! Event ID 9175, Event ID 9518, Event ID 8197 keep coming out
    By Application Development in forum Microsoft Exchange
    Replies: 2
    Last Post: 05-07-2004, 07:51 AM
  4. Host event sink + few questions (please help)
    By Application Development in forum Microsoft Exchange
    Replies: 0
    Last Post: 01-18-2004, 11:37 AM