Click here to Skip to main content
15,891,657 members
Articles / Desktop Programming / Windows Forms

Extending the ListBox to show more complex items

Rate me:
Please Sign up or sign in to vote.
4.57/5 (14 votes)
4 Sep 20062 min read 141.4K   11K   102  
This article shows how to extend the ListBox to show more complex items - for example, items with image and text areas.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace testexListBox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Image image1 = Image.FromFile(@"image1.jpg");
            Image image2 = Image.FromFile(@"image2.jpg");
            Image image3 = Image.FromFile(@"image3.jpg");
            exListBox1.Items.Add(new exListBoxItem(14, "John, the Tester", @"First details text is used to check it out, if text fits correctly the bounds of an item.
As you can see, everything fits nicely.
If it's shown correctly, that's should be last line, that you see.
If you can see this line, it looks like it overlaps something and there's a bug in the code.
", image1));
            exListBox1.Items.Add(new exListBoxItem(99,"Bill", "phone +345645464, fax +6546546546, email email@email.com", image2));
            exListBox1.Items.Add(new exListBoxItem(71, "Peter", "ICQ 56465464, msn hot@hotmail.com, phone +5465464654", image3));

        }

        private void exListBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
        }

        private void exListBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.Text = ((exListBoxItem)exListBox1.SelectedItem).Id.ToString();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Lithuania Lithuania
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions