Auto Complete on ComboBox, not working with user defined DrawItem!
Posted on 2008-10-01
I've got an issue with a Windows application I've written in C# using Visual Studio 2005. With the help of Expert's Exchange, I was able to create a fancy ComboBox that allows different colors for different items. With the use of a special class that was created, I do the following:
I SET / ADD the items in the ComboBox like this:
ListItemSC oItem = new ListItemSC();
oItem.SelColor = Color.Blue;
oItem.Text = strTempstr.ToUpper();
oItem.Value = dataReader["guidPersonID"].ToString();
I RETREIVE the items like this:
ListItemSC oItem = (ListItemSC)this.cBxPlayerList.SelectedItem;
String strValue = oItem.Value;
String strText = oItem.Text;
And I set the DrawItem event of the ComboBox to this:
private void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
System.Drawing.Color aColor = new System.Drawing.Color();
if (e.Index >= 0)
String drawString = this.cBxPlayerList.Items[e.Index].ToString();
Font drawFont = new Font("Veranda", 10, FontStyle.Bold);
aColor = ((ListItemSC)this.cBxPlayerList.Items[e.Index]).SelColor;
SolidBrush drawBrush = new SolidBrush(aColor);
PointF drawPoint = new PointF(e.Bounds.X, e.Bounds.Y);
e.Graphics.DrawString(drawString, drawFont, drawBrush, drawPoint);
cBxPlayerList.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
Everything works GREAT! Except I have ONE major problem....
Auto Complete no longer works.
The Auto Complete is currently set like this:
AutoCompleteMode = SuggestAppend
AutoCompleteSource = ListItems
DrownDownStyle = DropDownList
DrawMode = Normal
Something to note, BEFORE I programmed it to accept colors, etc... the auto complete worked PERFECTLY FINE... ever since I coded it to accept colors (using the DrawItem event) it no longer works.
Any idea what I can do?
Thanks guys, I really appreciate any help...