I'd like to have a ListBox control contain items that span multiple lines.
Essentially what I want is each item to span multiple lines and be selectable as one item. Is there a way to do this?
I'd like to have a ListBox control contain items that span multiple lines.
Essentially what I want is each item to span multiple lines and be selectable as one item. Is there a way to do this?
As suggested by LarsTech
in his comment, all the other comments lead to some kind of fully coded example which may confuse you. I made this demo with just some lines of code for you to follow and get started easily:
listBox1.DrawMode = DrawMode.OwnerDrawVariable;
//First add some items to your listBox1.Items
//MeasureItem event handler for your ListBox
private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
if (e.Index == 2) e.ItemHeight = 50;//Set the Height of the item at index 2 to 50
}
//DrawItem event handler for your ListBox
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
}