#Answer1
The DrawMode are: DrawMode.OwnerDrawVariable;
protected override void OnDrawItem(DrawItemEventArgs e)
{
if (Items.Count == 0 || e.Index == -1)
return;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
{
e.Graphics.FillRectangle(bgs, e.Bounds);
}
else
{
if (e.Index % 2 == 1)
e.Graphics.FillRectangle(bg1, e.Bounds);
else
e.Graphics.FillRectangle(bg2, e.Bounds);
}
LogDTO ld = (LogDTO)Items[e.Index];
String dato = ld.Dato.ToString();
SizeF stor = e.Graphics.MeasureString(dato, titlenFont);
e.Graphics.DrawString(dato, titlenFont, titelFarve, e.Bounds, StrengFormatDato);
String customer = ld.Customer1;
e.Graphics.DrawString(customer, titlenFont, titelFarve, new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width - 20, e.Bounds.Height), StrengFormatMedarbejder);
if (ld.Lejlighed1 == null)
e.Graphics.DrawImage(Properties.Resources.logFLille, new Rectangle(e.Bounds.Width - 15, e.Bounds.Y, 12, 12));
else
e.Graphics.DrawImage(Properties.Resources.logLLille, new Rectangle(e.Bounds.Width - 15, e.Bounds.Y, 12, 12));
Rectangle infoPlads = new Rectangle(infoIndryk, (int)(e.Bounds.Y + stor.Height), e.Bounds.Width - infoIndryk, e.Bounds.Height);
e.Graphics.DrawString(ld.Tekst1, infoFont, infoFarve, infoPlads, StrengFormatDato);
}
protected override void OnMeasureItem(MeasureItemEventArgs e)
{
if (Items.Count == 0)
return;
LogDTO ld = (LogDTO)Items[e.Index];
int datoHojde = (int)e.Graphics.MeasureString("Some text to calculate the height", titlenFont).Height;
int infoTekstHojde = (int)e.Graphics.MeasureString(ld.Tekst1, infoFont, new SizeF(Width - infoIndryk, 1000), StrengFormatDato).Height;
e.ItemHeight = datoHojde + infoTekstHojde;
}
Sorry for some non-english words... Some of the references are written in danish.
the code shows the MeasureItem event handler, and the OnDrawItem event handler... Hope you can understand the code, regardless some words are danish :)