I am not much of a desktop developer, but I have been getting into it with windows forms and C#.. and I have run into something that seems perplexing to me.

I am creating a windows control that derives from ListView, and I am adding drag and drop functionality that will draw a line between items in the list to indicate where an item that is dropped will be inserted.

My original approach was that upoin DragEnter being fired, I would set a Bitmap that is a priv class member to the current bitmap of the control.. I am doing this like so:

this.ctrlbmp = new Bitmap(this.Width, this.Height, this.CreateGraphics());

Then each time the DragOver event fires, I calculate based on the current Y position of the mouse, where to draw my line, and draw the bitmap on top of the control like such:

this.CreateGraphics().DrawImage(bmp,0,0,this.Width,this.Height);

I would then call this.Refresh() when DragLeave fires.

The problem I have gotten into, seems to have to do with invalidating the control. The effect I get is that each line draws but is never removed as I drag across the list. I thought that it would be taken care of by repainting the entire control each time.

If anyone can suggest reference material, or perhaps explain a more experienced approach, I would appreciate it greatly.