Good afternoon, everyone. I've subclassed ListBox to draw an icon next to
each line, and it works! Except for one thing... when drawing items, it
seems that SelectedItems and SelectedIndices is not perfectly current. This
means that if I use it to draw, in some cases I may draw an item highlighted
when it shouldn't be, or vice-versa. This mostly happens when dragging to
select multiple entries.
My temporary solution is to force a Refresh after every SelectionChanged
event, but this makes the list less responsive. Basically, I'd like it to
paint just like a normal listbox.
So far I've only used this with an extended multi-select list box.
This is the relevant code in my subclass:

// Constructor:
...
DrawMode = DrawMode.OwnerDrawFixed;
DrawItem += Draw;
SelectedIndexChanged += SelectionChange;
...
// Handlers:
protected void Draw(object sender, DrawItemEventArgs args)
{
args.DrawBackground();

int row = args.Index;
Graphics graphics = args.Graphics;
Rectangle bounds = args.Bounds;

if (row != -1)
{
object item = Items[row];

// Draw the icon, if any
Image icon = GetIconForItem(item);
if (icon != null) graphics.DrawImage(icon, bounds.Location);

// Draw the text, if any
string text = item.ToString();
if (text.Length > 0)
{
int textHeight = Font.Height;
int offSet = (ItemHeight - textHeight) >> 1;
Brush brush = new SolidBrush(SelectedItems.Contains(item) ?
SystemColors.HighlightText : ForeColor);

graphics.DrawString(text, Font, brush, ICON_SIZE + 1.0F,
(float)(bounds.Top + offSet));
}
}

args.DrawFocusRectangle();
return;
}
protected void SelectionChange(object sender, EventArgs args)
{
Refresh();
return;
}

Any ideas from the Windows Forms gurus? Thanks!