Hi Morten,
I did as u said, but still i can't show image with text :-(
I added a imageList and added the images in that and assiciated with
combobox , where am i going wrong
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string[] items;
items = new string[ComboBoxImageList.Images.Count];
for (int i = 0; i < ComboBoxImageList.Images.Count; i++)
{
this.comboBox1.Items.Add(ComboBoxImageList.Images
);
}
this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
this.comboBox1.DrawMode = DrawMode.OwnerDrawVariable;
this.comboBox1.ItemHeight =
this.ComboBoxImageList.ImageSize.Height;
this.comboBox1.Width =
this.ComboBoxImageList.ImageSize.Width + 80;
this.comboBox1.MaxDropDownItems =
this.ComboBoxImageList.Images.Count;
}
private void comboBox1_DrawItem(object sender,
DrawItemEventArgs e)
{
if (e.Index != -1)
{
e.Graphics.DrawImage(this.ComboBoxImageList.Images[e.Index],
e.Bounds.Left, e.Bounds.Top);
}
}
}
}
Regards
-Sajin
You need to specify DrawMode. OwnerDrawFixed is usually good enough, but use OwnerDrawVariable if the height of the items can vary.
Set DropDownStyle to DropDownList to be able to draw the selected item in the EditBox
Then subscribe to the ComboBox' DrawItem event. It will be called for each item in the list. Use the DrawItemEventArgs to find out what kind of item you are currently drawing and use DrawItemEventArgs.Bounds to position your drawing. You can then draw image and text any way you like. DrawItemEventArgs.State has information of wether the current item is highligted and so on.
If you need more specific information, please ask.