Hi,
You need to implement ownerdrawing of the items, which means setting
DropDownStyle to DropDownList, and DrawMode to OwnerDrawFixed. Then you
need to implement the DrawItem event and code similar to the below
private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if ((e.State & DrawItemState.ComboBoxEdit) > 0)
{
e.Graphics.DrawString("One, Two", comboBox1.Font,
SystemBrushes.ControlText, e.Bounds.Left, e.Bounds.Top);
}
else if (e.Index > -1)
{
if (comboBox1.Items[e.Index].ToString() == "Two")
e.Graphics.DrawString("V", comboBox1.Font,
Brushes.Green, e.Bounds.Left, e.Bounds.Top);
e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(),
comboBox1.Font, SystemBrushes.ControlText, e.Bounds.Left + 20,
e.Bounds.Top);
}
}
This will draw "One, Two" in the EditBox if DrawItemEventArgs.State
contains DrawItemState.ComboBoxEdit. Replace "One, Two" with some method
calculating which language is selected.
For the rest of the items it will simply draw the item name, with the
names pushed right 20 pixels, and draw a V in front of "Two" indicating
that "Two" is selected. Instead of using DrawString to draw a V, use
DrawImage with an image of a check mark.
e.DrawBackground() takes care if the selected background color, but to
highlight the text of the selected line, use e.State to determine when
this should occur. Tip, use DrawItemState.Focus and
SystemBrushes.HighlightText
I need to select multiple entries in the drop down list.
E.g. Search a string in languages like C#, VB, Java etc. These entries
are in drop down. So i need to multi select to search in multiple
languages
1. One of the option could be to have a check box beside each entry in
drop down. Do any one have an idea how to do this. Solution in C# is
required but even if its unmanaged code is OK.
2. Do any one have another idea for this multi select problem.